繁体   English   中英

固定位置div,如果在屏幕上显示div,则切换到相对位置

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM