简体   繁体   中英

ScrollTop Jquery not working properly

I have been using the ScrollTop JQuery so that when buttons are clicked in the right hand column, they scroll to the specific id in the left. It goes to the specific id when I first load the page, but after that it doesn't go to the other three, but glitches out going up or down slightly when buttons are clicked. I found that when I scroll to the top of the page and click the link it goes to the correct place, so it seems it it trying to find the top position of the left column and trying to go from there. No ideas as to how to fix this so would appreciate any thoughts.

CSS:

html,
body {
height: 100%;
margin: 0px auto;
}


#main,
#col_l,
#col_r
{
height: 100%;
}

div[id*="col"]{
float: left;
width: 50%;
overflow: auto;
}   

#col_r{
overflow:hidden;
position:relative;
}   

JS:

<script src="jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="jquery.scrollTo-1.4.3.1-min.js" type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function() {      

$("#stsp").click(function() {
$('#col_l').animate({
scrollTop: $("#lgg").offset().top}, 2000);
});

$("#fg").click(function() {
$('#col_l').animate({
scrollTop: $("#funny").offset().top}, 2000);
}); 

$("#covers").click(function() {
$('#col_l').animate({
scrollTop: $("#coverso").offset().top}, 2000);
});

$("#demo").click(function() {
$('#col_l').animate({
scrollTop: $("#mp3").offset().top}, 2000);
});

});

HTML:

<div id="col_r">

<div id="hb"><a href="Foreigner.zip"><button id="demo">One &times; Fifteen (64mb)   </button></a></div>
<div id="lg"><button id="stsp">Same Time Same Place</button></div>
<div id="fg"><button id="funny">Funny Games Funny Games</button></div>
<div id="c"><button id="covers">Covers Over Covers</button></div>

</div>  

This was fixed this using the ScrollTo Jquery: http://flesler.com/jquery/scrollTo/

I'm not sure why I was having problems with the ScrollTop Jquery.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM