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]+'离开');
              }

            });
          }
  • 相关阅读:
    每日日报24
    每日日报23
    每日日报22
    链路层:MAC 地址
    应用层:电子邮件
    应用层:HTTP 协议
    应用层:DNS 域名系统
    运输层:TCP 拥塞控制
    运输层:拥塞控制原理
    JAVA学习日记26-0731
  • 原文地址:https://www.cnblogs.com/hope-markup/p/6624573.html
Copyright © 2011-2022 走看看