我有一个静态的body元素和一个DIV,其高度为500px。它有溢出:可见和文本超过500px。我想滚动那个DIV,而鼠标指针在身体上方(它本身没有任何滚动条)。
任何指示?
Pic related - 鼠标指针在我要滚动的DIV之外
答案 0 :(得分:0)
你可以尝试一下
$(document).ready(function(){
if ($('selector:hover').length != 0) {
$(document).scrollTo('selector');
}
});
答案 1 :(得分:0)
好的,我找到了。对于找到这个帖子的人来说:
/** This is high-level function.
* It must react to delta being more/less than zero.
*/
function handle(delta) {
var target = $('#scrollable_content');
var top = target.scrollTop() - delta;
target.scrollTop(top);
}
/** Event handler for mouse wheel event.
*/
function wheel(event){
var delta = 0;
if (!event) /* For IE. */
event = window.event;
if (event.wheelDelta) { /* IE/Opera. */
delta = event.wheelDelta/120;
} else if (event.detail) { /** Mozilla case. */
/** In Mozilla, sign of delta is different than in IE.
* Also, delta is multiple of 3.
*/
delta = -event.detail/3;
}
/** If delta is nonzero, handle it.
* Basically, delta is now positive if wheel was scrolled up,
* and negative, if wheel was scrolled down.
*/
if (delta) handle(delta);
/** Prevent default actions caused by mouse wheel.
* That might be ugly, but we handle scrolls somehow
* anyway, so don't bother here..
*/
if (event.preventDefault) event.preventDefault();
event.returnValue = false;
}
if (window.addEventListener) window.addEventListener('DOMMouseScroll',
wheel, false);
window.onmousewheel = document.onmousewheel = wheel;