使用 .load 实现 jQuery 闪烁

发布于 2024-08-27 11:39:12 字数 305 浏览 11 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

羁拥 2024-09-03 11:39:12

闪烁可能是由于 #content div 的尺寸在加载之间有所不同而引起的,请尝试在加载之前滑动它或在加载之间使用其他过渡

例子 :

$(document).ready(function(){
    $('a').click(function() {      
    $('#content').slideUp('slow',function(){
       $('#content').load($(this).attr("href"),function(data){
          $('#content').slideDown('slow'); 
      });
  })
  return false;
}); 
});

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 :

$(document).ready(function(){
    $('a').click(function() {      
    $('#content').slideUp('slow',function(){
       $('#content').load($(this).attr("href"),function(data){
          $('#content').slideDown('slow'); 
      });
  })
  return false;
}); 
});
此刻的回忆 2024-09-03 11:39:12

我希望质疑这个前提是可以的。您要让所有链接都使用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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文