This jQuery code is working well, but I want to implement a fixed point, I want to replace the 510 with a relative point, from css: #content
var _rys = jQuery.noConflict();
_rys("document").ready(function () {
_rys(window).scroll(function () {
if (_rys(this).scrollTop() > 510) {
_rys('.navigation').addClass("fixed");
} else {
_rys('.navigation').removeClass("fixed");
}
});
});
I converted this code, but its not working, and I did not realize why :) Thanks for the help in advance.
jQuery(document).ready(function() {
var aboveHeight = $('header').outerHeight();
$(window).scroll(function(){
if ($(window).scrollTop() > aboveHeight){
$('.navigation').addClass("fixed");
}
else {
$('.navigation').removeClass("fixed");
}
});
});
The working version: thanks Dinesh Kumar DJ
jQuery(window).load(function() {
var aboveHeight = jQuery('#content').offset().top;
console.log(jQuery('#content'));
jQuery(document).scroll(function(){
if (jQuery(window).scrollTop() > aboveHeight){
jQuery('.navigation').addClass("fixed");
} else {
jQuery('.navigation').removeClass("fixed");
}
}); });
Replace all $ by jQuery, it will work fine,
jQuery(document).ready(function() {
var aboveHeight = jQuery('header').outerHeight();
jQuery(window).scroll(function(){
if (jQuery(window).scrollTop() > aboveHeight){
jQuery('.navigation').addClass("fixed");
} else {
jQuery('.navigation').removeClass("fixed");
}
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.