My problem is when I click on a (fixed position) div to animate another div the entire page jumps to the top. I have tried preventDefault and return false, but nothing seems to fix the problem! Please help.
Here is the script
$(document).ready(function(){
$("#close").click(function(){
$("#info").animate({
width: "0",
height:"0"
}, 100 );
$("#info").hide(),
$(".container").animate({
left:"0",
width:"100%"
}, 100 );
return false;
});
$(".sidebar").click(function(evt){
evt.preventDefault();
$("#info").show(),
$("#info").animate({
width: "25%",
height:"100%",
left:"0"
}, 100 );
$(".container").animate({
left: "25%",
width:"75%"
}, 100 );
return false;
});
});
If the trigger element is an empty anchor
then the location hash changes to “#” after clicking it. By not finding an area that corresponds with an empty hash, the browser scrolls the page to the top.
Here’s what you can do:
Or you could do it like they did 10 years ago: change the empty anchor href to an empty javascript statement:
update
After looking at the markup, I’ve got the solution. All you have to do is to make sure that your
.containerhas the ability to scroll. While animating, the elements gets the css propertyoverflow : hidden(i don’t really know where it gets it from) and that kind of resets your scroll position. So, all you have to do is to add this to your stylesheet: