比方說,您有一個包含大量內容的工具提示,因此您需要將其滾動。當然,你不能移動鼠標來滾動工具提示,因爲當你用你的瀏覽器離開時,工具提示會隱藏起來。如何使用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是可滾動的,所以不完全。但是,謝謝! –