Created
October 11, 2020 22:10
-
-
Save fhdalikhan/0a0a119f7b07657a583161ec3848046c to your computer and use it in GitHub Desktop.
For Removing Class and Adding Class based on the scroll position
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="menuBar" class="nav-menu"></div> | |
<div style="margin-bottom: 999em;"></div> | |
<script type="text/javascript"> | |
$(document).ready(function(){ | |
$(window).on('scroll', function () { | |
var $body = $('body'); | |
var $target = $('#menuBar'); | |
if ($body.scrollTop() > 100 && $target.hasClass('nav-menu')){ | |
$target.removeClass("nav-menu"); | |
} | |
else if( $body.scrollTop() <= 100 && !$target.hasClass('nav-menu') ){ | |
$target.addClass('nav-menu'); | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment