简体   繁体   中英

Scrollspy jquery doesn't work in firefox, opera

Please help me with this problem. My script doesn't work in firefox and opera, it work's only in chrome. http://jsfiddle.net/suenot/2Fju6/3/

$(document).ready(function() {
    var navsPosition = $('#goods-navs').position().top;
    $(window).scroll(function() {
        if ( $('body').get(0).scrollTop > navsPosition) {
            $('#goods-navs').addClass('active');
        } else {
            $('#goods-navs').removeClass('active');
        }
    });
});

Try:

$(document).ready(function() {
    var navsPosition = $('#goods-navs').position().top;
    $(window).scroll(function() {

        if ( $(window).scrollTop() > navsPosition) {
            $('#goods-navs').addClass('active');
        } else {
            $('#goods-navs').removeClass('active');
        }
    });
});

use "$(window).scrollTop()" instead of "$('body').get(0).scrollTop"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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