我遇到以下問題。我有一個DIV single-help
,它從-300px
動畫到0px
當滾動從頂部900px
。我正在使用此代碼。Div出現在> 900px滾動並停在頁腳div
jQuery(window).scroll(function() {
var delayms = "900"; // mseconds to stay color
if (jQuery(this).scrollTop() > 900) {
jQuery('.single-help').stop().animate({ bottom: '0px' });
} else $(".single-help").click(function (e) {
jQuery('.single-help').stop().animate({ bottom: '-300px' });
jQuery('.single-help').css('display','none').delay('delayms');
})
});
這一切都有效,當我滾過900px
時,DIV出現。但是當我到達頁面的頁腳時。它涵蓋了footer
DIV。現在我試圖讓.single-help
DIV在到達頁腳時停止。對於我正在使用此代碼:
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() > $(document).height() - 200) {
jQuery('.single-help').stop().animate({ bottom: '0px' });
$('.single-help').addClass('fixed_button');
}else{
$('.single-help').removeClass('fixed_button');
}
});
而這個CSS:
.fixed_button{
position:absolute !important;
margin-top:1900px;
bottom: 270px !important;
}
這不過去頁腳內容停止DIV。但是,現在的問題。當我到達頁面底部並向上滾動時,看起來代碼jQuery('.single-help').stop().animate({ bottom: '0px' });
正在重複。該DIV single-help
跳轉到300px
和左右動畫回落到0px
。我不明白爲什麼會發生這種事。
有誰知道如何解決這個問題,或者告訴我更多關於這是爲什麼?我認爲這可以做得更簡單...謝謝。
我做了一個小提琴,我沒有像我的網站一樣工作,但它確實表明,當您滾動到頂部時,動畫會重複兩次。 https://jsfiddle.net/r31dnqm9/
什麼是擺脫'.stop()'的結果? –
如果我刪除了所有的stop(),它仍然會執行第二個動畫。所以沒有改變...(我刪除了我的評論,因爲我認爲它的工作,但它沒有)。 –
你可以創建一個jsfiddle嗎? –