/*
* 获取元素移动的方向
* @param $element 元素的jQuery对象
* @param event 事件对象
* @return direction 返回一个数字:0:上,1:右,2:下,3:左
**/
function getDirection($element, event) {
var w = $element.width(),
h = $element.height(),
x =
(event.pageX - $element.offset().left - w / 2) *
(w > h ? h / w : 1),
y = (event.pageY - $element.offset().top - h / 2) * (h > w ? w / h : 1),
direction =
Math.round((Math.atan2(y, x) * (180 / Math.PI) + 180) / 90 + 3) % 4;

return direction;
}

$('#content')
.on('mouseenter', function (event) {
console.log('enter: ' + getDirection($(this), event));
})
.on('mouseleave', function (event) {
console.log('leave: ' + getDirection($(this), event));
});