A
A
Alexander Gamov2015-12-03 10:40:29
css
Alexander Gamov, 2015-12-03 10:40:29

How to overcome position:fixed on IOS?

There is a vertical block at 100vh, when scrolling to it, it should be fixed on the screen and when scrolling back to it, return to its place. To do this, I use the sticky.js plugin. But position: fixed on IOS on old smartphones does not behave quite adequately.
There is a good solution on Habré , but together with the plugin it is not entirely compatible.
On the desktop it works fine only when scrolling to the bottom, on the mobile it "jumps", and if you try to scroll back up, the bacchanalia begins.
Example HERE (at resolution less than 750px)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Beaver Nubyar, 2015-12-11
@Boberdober

Working shitcode. Can it be used?

jQuery(function() {
        var box = jQuery('.example'); // float-fixed block
        var top = box.offset().top - parseFloat(box.css('marginTop').replace(/auto/, 0));
        jQuery(window).scroll(function(){
            var windowpos = jQuery(window).scrollTop();
            if(windowpos < top) {
                box.css('position', 'static');
            } else {
                box.css('position', 'fixed');
                box.css('top', 0);
            }
        });
    });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question