I am currently facing an issue with scrolling on my website. Visit this site to see the problem. When scrolling down, it causes the "hidden" part of the site to slide up. I want to achieve a similar sliding effect, but it needs to be smooth. I have attempted to use scrollTop() and animate(), but they do not seem to work for me. I am utilizing JQuery for this task. Below is the code I have implemented:
HTML
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
<link href="stylin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$(".button").toggle(function(){
$("#blocks").animate({top: 200}, 500 );
},
function(){
$("#blocks").animate({top: 760}, 500 );
});
});
</script>
<script type="text/javascript">
$(document).ready( function() {
$(document).scroll( function() {
$("#blocks").animate({top: (780-$(this).scrollTop())}, 1000 );
});
});
</script>
</head>
<body>
<div id="main">
<div id="photo">
</div>
<div id="blocks">
<div id="button_block">
<a href="#" class="button" ><img src="scrollup.png" /></a>
</div>
</div>
</div>
</body>
</html>
CSS
#main {
width: 1500px;
position:absolute;
}
#photo{
position:fixed;
top:0;
width:1500px;
height:780px;
background-color:blue;
z-index:0;
}
#blocks{
position:absolute;
top: 760px;
width: 100%;
height: 1000px;
background-color: red;
z-index:1;
}
#button_block{
position:absolute;
width:100%;
height:64px;
top:-32px;
}
.button
{
display:block;
position: absolute;
right: 686px;
}
The blocks div should be sliding up while scrolling.
Focus on this section:
<script type="text/javascript">
$(document).ready( function() {
$(document).scroll( function() {
$("#blocks").animate({top: (780-$(this).scrollTop())}, 1000 );
});
});
</script>