I have a problem with a link on one page. It works when I want to scroll down, but when I want to scroll up, it will stay in the same place. This is part of the code:
(function($){
var d1 = $('.one');
var d1orgtop = d1.position().top;
var d2 = $('.two');
var d2orgtop = d2.position().top;
var d3 = $('.three');
var d3orgtop = d3.position().top;
var d4 = $('.four');
var d4orgtop = d4.position().top;
$(window).scroll(function(){
var st = $(window).scrollTop();
if (st >= d1orgtop) {
d1.addClass('latched');
} else {
d1.removeClass('latched');
}
if (st >= d2orgtop) {
d2.addClass('latched');
} else {
d2.removeClass('latched');
}
if (st >= d3orgtop) {
d3.addClass('latched');
} else {
d3.removeClass('latched');
}
if (st >= d4orgtop) {
d4.addClass('latched');
} else {
d4.removeClass('latched');
}
});
And an example in JSFIDDLE JSFIDDLE
When I click href on top of the page, it scrolls down. But when I click href below, nothing happens. Where is my fault?
source
share