![](/img/trans.png)
[英]Limiting the scrolling of left and rights with jquery to stop overscroll
[英]Stop Scrolling if there is no Content left
當div中沒有更多內容時,如果要單擊該腳本,我希望停止滾動。
$(document).ready(function () {
$("#right").click(function () {
var leftPos = $('.DivDataMain').scrollLeft();
$(".DivDataMain").animate({scrollLeft: leftPos + 250}, 800);
});
$("#left").click(function () {
var leftPos2 = $('.DivDataMain').scrollLeft();
$(".DivDataMain").animate({scrollLeft: leftPos2 - 250}, 800);
});
});
這是演示鏈接: FIDDLE
在演示中,盡管div不再顯示任何內容,但它仍繼續滾動到右側。 我希望它停止。
提前致謝。
您必須在#midleBody
元素中添加white-space: nowrap
並從其中刪除width: 90000px
。
發生的情況是您的元素具有固定的寬度,因此您的JavaScript會檢測到它並一直持續到最后。 您需要根據元素中的文本動態調整元素,這就是white-space:nowrap
作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.