比方说,您有一个包含大量内容的工具提示,因此您需要将其滚动。当然,你不能移动鼠标来滚动工具提示,因为当你用你的浏览器离开时,工具提示会隐藏起来。如何使用jQuery手动滚动div?
<!-- Let's assume this is my tooltip and -->
<div id="scrollableTooltip">
<p>foo bar foo bar foo bar foo bar foo bar foo bar
foo bar foo bar foo bar foo bar foo bar foo bar
foo bar foo bar foo bar... ∞ </p>
</div>
<div id="triggerDiv">
<!-- When I hover and scroll here, I want to scroll my tooltip -->
<p>Scroll inside me to trigger scroll in div above...</p>
</div>
我曾尝试以目标的mousewheel DOMMouseScroll
事件以下,然后使用jQuery尝试在我的提示div来触发滚动 - 但没有任何成功(Please see my JSFiddle):
$('#triggerDiv')
.on('mousewheel DOMMouseScroll', function (e){
console.log("Scroll was triggered...", e);
// 1.
$('#scrollableTooltip').scroll();
// 2.
// $('#scrollableTooltip').trigger('scroll');
});
CSS
#scrollableTooltip {
border: 1px solid red;
height: 100px;
overflow-y: scroll;
margin-bottom: 30px;
}
#triggerDiv {
border: 1px solid red;
height: 200px;
}
您正在寻找这样的事情? http://stackoverflow.com/questions/9236314/how-do-i-synchronize-the-scroll-position-of-two-divs – Woodrow
在我的情况下,只有顶部div是可滚动的,所以不完全。但是,谢谢! –