简体   繁体   中英

scroll fixed position = jQuery Jank with offset top in safari

I'm trying to get 2 sets of classes to have fixed positions in jQuery.

$(window).scroll(function(){

    $(".staticTextGrid").each(function(){

        $(this).css('margin-top',($(window).scrollTop() - $(this).parent().offset().top+160));

    });
    $(".staticTextGridTop").each(function(){

        $(this).css('margin-top',($(window).scrollTop() - $(this).parent().offset().top));

    });
});

This is what I'm doing but it doesn't want to play nice in safari (causing it to jank and jitter). Any points in the right direction would be great. My thanks in advance.

You haven't said what safari is doing that isn't playing nice so I can only have a stab at it. But sometimes safari doesn't render the page again on a css change. try adding this to the end of your function. It's not the best solution but it will at least confirm the problem! :)

$("body").addClass("tempClass").removeClass("tempClass");

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