Search code examples
javascriptjqueryoffset

Offset Top Not Working In IOS


Here is the complete code http://jsfiddle.net/vinex08/uhm26em1/

jQuery(function ($) {
var distance = $('.c').offset().top,
    $window = $(window);

$window.scroll(function () {
    if ($window.scrollTop() >= distance) {
        $(".b").css({
            position: 'fixed',
            top: '0'
        });
    } else {
        $(".b").css({
            position: 'inherit',
            top: '10'
        });
    }
});
});`

It's working on Chrome and Firefox but when i checked it via iPad AIR and iPhone, the effect executes even before the 'class c' hits the top.


Solution

  • I hope this will help:

    jQuery(function ($) {
        var distance = $('.c').offset().top;
        $(window).scroll(function () {
            var wndwTop = $(this).scrollTop();
            if (wndwTop >= distance) {
                $(".b").css({
                    position: 'fixed',
                    top: '0'
                });
            } else {
                $(".b").css({
                    position: 'inherit',
                    top: '10'
                });
            }
        });
    });