📜  jquery中的窗口滚动位置固定位置 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:04:08.748000             🧑  作者: Mango

代码示例1
$(function() {
    var fixadent = $("#fixadent"), pos = fixadent.offset();
    $(window).scroll(function() { 
        if ($(this).scrollTop() > (pos.top + 10) && fixadent.css('position') == 'static') {
            fixadent.addClass('fixed');
        } else {
        if ($(this).scrollTop() <= pos.top && fixadent.hasClass('fixed')) { 
        fixadent.removeClass('fixed');
    }
   })
});