Howdey,我需要创建一个方向感知悬停效果,但停留在正确的计算上。(这是计算问题还是错误的标记?)
这是我到目前为止所做的:
左右箭头按预期工作,但向上和向下失败。任何想法我做错了什么?
$("#circle").on('mousemove', function(e) {
var elem = $(this),
arrowT = $('.arrow.top'),
arrowR = $('.arrow.right'),
arrowB = $('.arrow.bottom'),
arrowL = $('.arrow.left'),
offset = elem.offset(),
pageX = e.pageX - offset.left,
pageY = e.pageY - offset.top,
side = {
top: pageY < (elem.height() / 2),
left: pageX < (elem.width() / 2),
bottom: pageY > (elem.height() / 2),
right: pageX > (elem.width() / 2)
};
arrowT.css({
top: side.top ? pageY - arrowT.outerHeight() : null
});
arrowR.css({
right: side.right ? -(pageX - (elem.width() - arrowR.outerWidth())) : null
});
arrowB.css({
bottom: side.bottom ? -(pageY - (elem.height() - arrowB.outerHeight())) : null
});
arrowL.css({
left: side.left ? pageX - arrowL.outerWidth() : null
});
});