changing an elements css position after scrolling down the page

后端 未结 3 2090
遥遥无期
遥遥无期 2020-12-14 04:37

I am messing around with some jquery trying to get to grips with it.

I have a ul nav which has a absolute position set but after I scroll the page down by 200 pixels

3条回答
  •  心在旅途
    2020-12-14 05:03

    Thanks to everyone for being so quick to help

    this is what i wanted

    $(document).ready(function() {
        var theLoc = $('ul').position().top;
        $(window).scroll(function() {
            if(theLoc >= $(window).scrollTop()) {
                if($('ul').hasClass('fixed')) {
                    $('ul').removeClass('fixed');
                }
            } else { 
                if(!$('ul').hasClass('fixed')) {
                    $('ul').addClass('fixed');
                }
            }
        });
    });
    

    i got it from

    http://www.defringe.com/

    http://satbulsara.com/tests/

    Thankss!!!!!

提交回复
热议问题