[英]Is it possible to know when scrolling a div with overflow: scroll reached the end?
[英]how to know when a div scroll horizontally has reached an end
我真正想要實現的是檢測div何時滾動到末尾,然后將其返回到div的開始。 當div自動滾動時,我想將left設置為0,因此返回到div的開頭,當div由prev和next按鈕控制時,在到達末尾時停止,在到達末尾時停止正確的結束。 但是我能做的一小段代碼是向左和向右滾動,但是在結束時可以將其停止,對此方法的任何幫助將不勝感激,謝謝
var sliderWidth = $(".dialyDealSlider").width();
var ddslider = $(".dialyDealSlider");
var BoxWidth = $(".dialyDealBox").width();
$(".ddslider-prev").click(function() {
//alert(BoxWidth);
var leftPos = ddslider.scrollLeft();
var newWidth = leftPos - BoxWidth;
alert(BoxWidth);
ddslider.animate({
left: "-=" + newWidth + "px"
}, 800);
});
$(".ddslider-next").click(function() {
//alert('next');
var leftPos = ddslider.scrollLeft();
var newWidth = leftPos + BoxWidth;
alert(newWidth);
ddslider.animate({
left: "-=" + newWidth + "px"
}, 800);
});
dailyDeal();
function dailyDeal(finalWidth) {
var timer;
clearTimeout(timer);
scrollWidth = $(".dialyDealBox").width();
leftPosi = $(".dialyDealSlider").scrollLeft();
scrollWidth = leftPosi + scrollWidth;
$(".dialyDealSlider").animate({
left: "-=" + scrollWidth + "px"
}, 800);
timer = setTimeout(dailyDeal, 3000);
}
JS FIDDLE https://jsfiddle.net/sammyzeal/dcxvLgm0/
以下是我認為您正在尋找的兩個示例:
http://qnimate.com/detecting-end-of-scrolling-in-html-element/
兩者都很清楚,可以幫助您實現目標。
來自第一個鏈接的代碼:
<script type="text/javascript">
function scrolled(o)
{
//visible height + pixel scrolled = total height
if(o.offsetHeight + o.scrollTop == o.scrollHeight)
{
alert("End");
}
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.