大家好
我的意思是,当鼠标移向窗口边缘(x 或 y 或两者)时,我希望页面滚动,当鼠标停止移动时,我希望页面停止滚动。
有很多关于如何基于使用 onClick 事件或窗口边缘的滚动区域进行滚动的示例,但基于鼠标光标的移动的示例并不多。
任何帮助将非常感激。
网页已经被设计为使用滚动条、页面/主页/结束/箭头键等进行滚动。是否有任何原因不适合您的页面?改变预期的功能通常不是一个好主意。
您可以阅读mousemove http://www.quirksmode.org/js/events_mouse.html#mousemove活动在这里。无论如何,下面的代码应该可以工作,但我really不建议使用它。对于拥有敏感小鼠的人来说,这尤其会让人迷失方向:
// Variables for current position
var x, y;
function handleMouse(e) {
// Verify that x and y already have some value
if (x && y) {
// Scroll window by difference between current and previous positions
window.scrollBy(e.clientX - x, e.clientY - y);
}
// Store current position
x = e.clientX;
y = e.clientY;
}
// Assign handleMouse to mouse movement events
document.onmousemove = handleMouse;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)