使用 .load 实现 jQuery 闪烁
我正在使用 jQuery 使用 .load() 函数将 php 页面动态加载到我的页面中,到目前为止,这已经成功了,但是如果您单击各种链接以使用 .load() 更新 div,它就会开始在新点击的页面和旧页面,这很烦人,有人解决了吗?
当前代码:
$(document).ready(function(){
$('a').click(function() {
$('#content').load($(this).attr("href"));
return false;
});
});
I'm using jQuery to dynamically load php pages into my page using the .load() function, so far this has been successful but if you click on various links to update the div with the .load() it starts to flicker between the new clicked page and the old one, this is pretty annoying and has anyone got a fix?
Current code:
$(document).ready(function(){
$('a').click(function() {
$('#content').load($(this).attr("href"));
return false;
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
闪烁可能是由于 #content div 的尺寸在加载之间有所不同而引起的,请尝试在加载之前滑动它或在加载之间使用其他过渡
例子 :
The flickering is possibly caused because the dimensions of the #content div vary between loads, try to slideTogle it before loading or use another transition between loads
example :
我希望质疑这个前提是可以的。您要让所有链接都使用ajax 来替换#content 的内容吗?这不会破坏浏览器的前进/后退按钮行为吗?如果是这样,我个人不会喜欢使用这样的网站。
I hope it is ok to question the premise. You're making all links use ajax to replace #content's contents? Doesn't that break the browser's forward/back button behavior? If so, I personally would not like to use such a site.