Sunday, March 9, 2014

Set a div to be fixed from the top for the rest of the scroll.



var fixed = false;
        $(document).scroll(function() {
            if ($(this).scrollTop() >= 220) {
                if (!fixed) {
                    fixed = true;
        $('div').css({ position: 'fixed', top: 20 });                }
            } else {
                if (fixed) {
                    fixed = false;
                    $('div').css({ position: 'static' });
                }
            }
        });



No comments:

Post a Comment