当您单击链接时,它会加载正确的文件,但是如果您在#right中并向下滚动然后单击其他链接,它将不会加载到顶部,您必须滚动到顶部。当您点击任何链接时,有关如何将其加载到#right顶部的任何想法?
<script type="text/javascript" src="jquery-1.8.1.min.js"></script>
<style type="text/css">
#left,#right{
width:500px;
height:100px;
overflow: scroll;
overflow-x:hidden;
float:left;
}
</style>
<div id="left">
<ul>
<li><a class="page" id="one" href="one.html">One</a></li>
<li><a class="page" id="two" href="two.html">Two</a></li>
<li><a class="page" id="three" href="three.html">Three</a></li>
<li><a class="page" href="#">lskf</a></li>
</ul>
</div>
<div id="right"></div>
<script type="text/javascript">
$(document).ready(function(){
$('.page').click(function(e){
e.preventDefault();
var pg = $(this).attr('id');
var toLoad = $(this).attr('href');
var goin = $('#right').load(toLoad);
switch (pg){
case 'one':
goin;
break;
case 'two':
goin;
break;
case 'three':
goin;
break;
default: $('#right').load('test.html');
break;
}
});
});
</script>
答案 0 :(得分:0)
所以你可以在页面加载后滚动到顶部,
var goin = $('#right').load(toLoad, function() {
$(this).scrollTop(0);
});