在Firefox中动态数据加载后,页面跳转到顶部

时间:2014-08-27 07:20:46

标签: jquery

我使用PrettyPhoto灯箱。我的脚本被修改为在右侧显示注释。注释加载了Ajax调用(它不是iframe)。

Firefox中存在一个小问题。当我点击“加载更多注释”时,注释部分在Ajax加载数据后跳转到顶部。这很奇怪,因为它并不总是发生。 Simetimes它跳到顶部,有时不跳。

我花了很长时间试图在谷歌找到一个解决方案,但只有解决方案才能添加“cache:false”。我有它,但它没有帮助。

enter image description here

我在想,这可能是由网址中的PrettyPhoto主题标签引起的。我尝试使用没有深层链接的脚本,但它没有帮助。

问题仅出在PrettyPhoto模式框中。在正常页面中,评论加载没有任何问题。

“跳跃”问题仅在Firefox中存在。在Chrome中,MIE一切正常。

以下是加载更多评论的脚本:

$(document.body).on('click','.morecomments',function() {
var ID = $(this).attr("id");
if(ID) {
$("#more"+ID).html('<img src="/load.gif" />');
$.ajax({
type: "POST",url: "/more.php",
data: "vid="+ ID, 
cache: false,
success: function(html){
$("#more"+ID).remove();
$("div#comments_a").append(html);
}
});
} else {
$(".morec").html('-');
}
return false;
});

此脚本在PrettyPhoto框打开时加载第一条评论:

if (settings.comments=='1'){
$.ajax({
type: "GET",
url: "/comments-load.php",
data: "cid="+actual,
cache: false,
success: function(responce){    
if(responce) {
responce2=responce;
} else {
responce2='Error loading comments';
}
document.getElementById('PutCommentOut').innerHTML=responce2;
$('.pp_next').css({'margin-right':'0px','width':'49%'});
$('#PutCommentOut').css({'width':'100%','height':'100%','overflow-x':'hidden','overflow-y':'auto','padding-bottom':'0px'});
}
});
}

加载更多按钮:

<div id="comments_a">
    <div id="more1-5-2-0-0" class="morec"><a href="#" class="morecomments" id="1-5-2-0-0">Load more comments</a></div>
</div>

0 个答案:

没有答案
相关问题