我正在使用下面的函数来显示当前激活的gameList。现在的问题是,如果一个玩家正在浏览列表,如果执行了ajax调用,那么它会跳到div的顶部,我用ajax调用的响应替换了div。
如何避免跳转到div的顶部?或者任何其他应该实现的解决方案,以显示最新游戏的列表而不跳转到ajax调用?
(function pollServerForGameList() {
$.ajax({
url:"<?php echo Yii::app()->createUrl('game/getGameList') ?>",
data:{'id':<?php echo Yii::app()->request->getParam('id')?>},
type:"POST",
dataType:"html",
success:function(response){
$('.multiplayer').html(response);
},
});
setTimeout(pollServerForGameList, 2000);
}());用单行响应一些数据和按钮来加入游戏。
<ul>
<li class="first">Math</li>
<li>Rookie</li>
<li>Guest11</li><li>1</li>
<li class="last"><b><a id="Join" class="greenBtn" href="/game/multiple?id=4&gameid=20&diff=2&cat=4">Join the Game</a></b>
</li>
</ul>多行响应将有多个<
发布于 2013-07-24 17:25:05
您可以尝试保存当前滚动位置,然后在插入后返回到该位置。
(function pollServerForGameList() {
//Save current scroll position
var currPosition = $(window).scrollTop();
$.ajax({
url:"<?php echo Yii::app()->createUrl('game/getGameList') ?>",
data:{'id':<?php echo Yii::app()->request->getParam('id')?>},
type:"POST",
dataType:"html",
success:function(response){
$('.multiplayer').html(response);
//Return to the scroll position
$(window).scrollTop(currPosition);
},
});
setTimeout(pollServerForGameList, 2000);
}());https://stackoverflow.com/questions/17829729
复制相似问题