首页 > 其他 > 详细

判断鼠标移入元素方向

时间:2017-07-25 23:56:53      阅读:398      评论:0      收藏:0      [点我收藏+]
$(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{
  //移出
  }
})

  技术分享

判断鼠标移入元素方向

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!