Tuesday, 14 June 2016

Add and remove class to jquery onscroll

JS

<script type="text/javascript">

$(document).ready(function () {
    var start = $('#ruk').offset().top;
    $.event.add(window, "scroll", function () {
        var p = $(window).scrollTop();
        if( p > start ) {
            $('.subMenu').addClass('fixed');
        } else {
            $('.subMenu').removeClass('fixed');
        }
    });
});
</script>

HTML

<div id="ruk"></div>
<div class="subMenu">
<div class="inner">
         <p>TEST</p> 
</div>
</div>

Add and remove class to jquery onscroll

No comments:

Post a Comment