开发者

jQuery flicker using .load

开发者 https://www.devze.com 2022-12-25 13:58 出处:网络
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

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;
    }); 
});


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;
}); 
});


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消