码迷,mamicode.com
首页 > 其他好文 > 详细

判断鼠标移入元素方向

时间:2017-07-26 00:24:07      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:direction   判断   offset   技术   else   src   width   img   cti   

$(this).bind("mouseenter mouseleave",function(e){   
  var w = $(this).width();   
  var h = $(this).height();   
  var x = (e.pageX - $(this).offset().left - (w / 2)) * (w > h ? (h / w) : 1);   
  var y = (e.pageY - $(this).offset().top - (h / 2)) * (h > w ? (w / h) : 1);   
  var direction = Math.round((((Math.atan2(y, x) * (180 / Math.PI)) + 180) / 90) + 3) % 4;   
  //direction 0‘上方‘,1‘右侧‘,2‘下方‘,3‘左侧‘);
  if(e.type == ‘mouseenter‘){
  //移入
  }else{
  //移出
  }
})

  技术分享

判断鼠标移入元素方向

标签:direction   判断   offset   技术   else   src   width   img   cti   

原文地址:http://www.cnblogs.com/xiaomingSun/p/7236976.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!