2011-09-29 73 views
1

工作,我想使用 http://net.tutsplus.com/tutorials/javascript-ajax/how-to-load-in-and-animate-content-with-jquery/ 和修改它自己,我加的fancybox和tinyscrollbar它是工作在第一,但是,在我的一些网页就不再工作之间切换。我试图找到我的教程页面的评论回答,我用.live(),但它接缝它不工作,我不能找出解决方案, 听到的是我的代码:JavaScript并没有在动态Ajax内容

$(document).ready(function() {  
    var hash = window.location.hash.substr(1); 
    var href = $('#nav li a').each(function(){ 
     var href = $(this).attr('href'); 
     if(hash==href.substr(0,href.length-5)){ 
      var toLoad = hash+'.html #content'; 
      $('#content').load(toLoad) 
     }           
    }); 
    $('#nav li a').live ('click', function(){        
     var toLoad = $(this).attr('href')+' #content'; 
     $('#content').slideToggle('fast',loadContent); 
     $('#load').remove(); 
     $('#wrapper').append('<span id="load">LOADING...</span>'); 
     $('#load').fadeIn(500); 
     window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5); 
     function loadContent() { 
      $('#content').load(toLoad,'',showNewContent()) 
     } 
     function showNewContent() { 
      $('#content').show(500,hideLoader()); 
     } 
     function hideLoader() { 
      $('#load').fadeOut(500); 
     } 
     return false; 
    }); 


$("#scrollbar1").tinyscrollbar();   
$("a#example1").fancybox(); 

}); 

谢谢你, 安德鲁

回答

0

当没有一个完整的页面看,你很难看到你想做什么。但我认为问题是,当你加载新的内容时,你应该相应地更新滚动条和fancybox。

对于tinyscrollbar,您可以使用更新方法。

你可以看到如何在tinyscrollbar网站上使用它。

您可以尝试将它放入加载事件的成功回调中。

$(“#scrollbar1”)。tinyscrollbar_update();

您可以尝试将该规则放在hideLoader函数或showNewContent函数的末尾。

+0

我很感谢您的回答,但请您让我知道您还在寻找什么以及如何使用更新方法? – Norouzian