zoukankan      html  css  js  c++  java
  • angular学习笔记-angular中怎么获取dom元素

    步骤分解:

    第一步:给要获取的元素一个ng-model变量,并且绑定事件啦!

    1 <div class="home" ng-model="dirName"  ng-mouseenter="switchImage($event,dirName)"></div>  //给要获取的元素一个ng-model变量

    第二步:在controller中利用$event.target获取dom元素即可!

     1 $scope.switchImage = function($event, value) {  
     2            3             $($event.target).on("mouseenter mouseleave",function(e) {
     4                  var w = $(this).width(); // 得到盒子宽度
     5                  var h = $(this).height();// 得到盒子高度
     6                  var x = (e.pageX - this.offsetLeft - (w / 2)) * (w > h ? (h / w) : 1);
     7                  // 获取x值
     8                  var y = (e.pageY - this.offsetTop - (h / 2)) * (h > w ? (w / h) : 1);
     9                  // 获取y值
    10                  var direction = Math.round((((Math.atan2(y, x) * (180 / Math.PI)) + 180) / 90) + 3) % 4; 
                //direction的值为“0,1,2,3”分别对应着“上,右,下,左” 11 // 将点的坐标对应的弧度值换算成角度度数值 12 var dirName = new Array('上方','右侧','下方','左侧'); 13 if(e.type == 'mouseenter' && direction == 1){ 14 $(this).find('.profil-photo').html(dirName[direction]+'离开');

                }else{
                 $(this).find('.profil-photo').html(dirName[direction]+'离开');
              }

            });
          }
  • 相关阅读:
    windows7管理员权限
    Linux编程 第一个Hello World的C程序
    初步接触XCode和IPhone Simulator
    Android调用WCF
    mysql常用命令
    怎样利用Python制作守护进程
    Android模拟器如何设置DNS访问局域网内网站
    ubuntu下mysql攻略
    IIS7快速启动
    内存出错有时候是free后没有给指针赋NULL
  • 原文地址:https://www.cnblogs.com/hope-markup/p/6624573.html
Copyright © 2011-2022 走看看