[英]fixed position div, switch to relative if div on screen
腳本的真正新功能,如果這是基本的,那么道歉,但是...
我有2個position:fixed div,當特定的div在屏幕上可見時,我想成為position:relative。 (即,當顯示div時滾動到屏幕之外)
'antxt'-是默認的固定類,當屏幕上顯示'trig'時,我想切換到'andtxtscroll'。 我是根據沒有運氣的情況在此找到的。
$(window).scroll(function (event) {
var scroll = $(window).scrollTop();
$('andtxt').toggleClass('andtxtscroll',
scroll >= $('.trig').offset().top
);
});
//trigger the scroll
$(window).scroll();//ensure if you're in current position when page is refreshed
參見https://anthonynoyce.design/
當下一個視圖進入視圖時,我是否希望居中徽標向上滾動?
將$('andtxt')
更改$('andtxt')
$('.andtxt')
。 類選擇器之前應加.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.