script, , . script , .
: var navOffset = jQuery("nav").offset().top; "" , "nav".
: var navOffset = $(".nav").offset().top;
: jQuery(".status").html(scrollPos); "", .
("#status").html(scrollPos);
if/else, .nav "nav".
. : https://jsbin.com/lumabe/edit?html,css,js,output
The devil is in the details when it comes to manipulating the DOM with javascript!
Here is the complete, corrected script:
jQuery(document).ready(function() {
var navOffset = jQuery(".nav").offset().top;
jQuery(window).scroll(function() {
var scrollPos = jQuery(window).scrollTop();
jQuery("#status").html(scrollPos);
if (scrollPos >= navOffset) {
jQuery(".nav").addClass("fixed");
} else {
jQuery(".nav").removeClass("fixed");
}
});
});
Judah source
share