Created
April 17, 2014 11:34
-
-
Save xingmolu/10976085 to your computer and use it in GitHub Desktop.
判断鼠标从什么方向进入容器
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#wrap").bind("mouseenter,mouseleave", function() { | |
var w = $(this).width(); | |
var he = $(this).height(); | |
var x = (e.pageX - this.offsetLeft - (w / 2)) * (w > h ? (h / w) : 1); | |
var y = (e.pageY - this.offsetTop - (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" 分别对应着"上右下左" | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment