I want to move 4 objects of the DOM when a user scrolls the page.
you can check the page i'm talking about at this address:
http://www.tessuti-arredo.it/new/chi_siamo/rassegna/
as the user scrolls - i'm using $(window).scroll(function() - i check if the window.scrollTop is more than 10 pixels to move some objects. This seems to work fine. but on the ELSE statement (i mean when scrollTop is minor than 10 pixels) - and theese objects should move back to the original position - i have a strange behaviour, especially on two of the 4 objects i move (two fixed objects that i move together calling their class).
maybe it's a bit complicated to explain with my poor english, but if you have a look at the address i posted above it's quite easy to understand, just try to scroll the page.
The objects i want to move are: - a link (a) object contained inside the #header div = $("#header h1 a") - the left sidebar menu called with his id = $("#sidebar") - and two fixed divs, the main horizontal menu and his background, called by their class = $(".moveMenu")
One important last thing: with Firefox it seems to be ok, with all other browsers i have a variable delay that looks like some error on my code.
speaking about my code, here it is:
$(document).ready(function(){
$(window).scroll(function(){
if($(this).scrollTop() > 10) {
$("#sidebar").stop().animate({top:'119px'}, 100, function (){
// some callback
});
$("#header h1 a").stop().animate({marginTop:'30px'}, 100, function (){
// some callback
});
$(".moveMenu").stop().animate({top:'0'}, 300, function (){
// here i change the class of fixed objects to call them back on else statement
$(this).removeClass('moveMenu').addClass('moveMenu2');
});
}else{
// this is happening with unwanted delay
$(".moveMenu2").stop().animate({top:'90'}, 300, function (){
$(this).removeClass('moveMenu2').addClass('moveMenu');
});
$("#sidebar").stop().animate({top:'89px'}, 100, function (){
$(this).css({'padding-top' : '40px'});
});
$("#header h1 a").stop().animate({marginTop:'0px'}, 100, function (){
// some callback
});
}
});
});
I know there are some empty callbacks, i just kept them to have it ready to fill with something, i tryed to delete them, nothing is changed.
another thing i tryed is to call the two delaying object with a specific id instead of class but nothing has gone better...
i really hope you will find some error in my coding, i know i'm not so good.