简体   繁体   English

ScrollTop Jquery无法正常工作

[英]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. 我一直在使用ScrollTop JQuery,以便在右列中单击按钮时,它们会滚动到左侧的特定ID。 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. 当我第一次加载页面时,它会转到特定的id,但是此后不会转到其他三个页面,而是在单击按钮时会稍微向上或向下滑动。 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: 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: 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: 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/ 使用ScrollTo Jquery对此进行了修复: http : //flesler.com/jquery/scrollTo/

I'm not sure why I was having problems with the ScrollTop Jquery. 我不确定为什么ScrollTop Jquery有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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