2010-06-25 123 views
0

我使用jQuery加载函数从外部加载图像..但不能添加灯箱..如何添加灯箱图片在jQuery中外部加载?

我对jquery很新颖。

var href = $('#images').attr('href'); 

$('#images').click(function(){ 
    var toLoad = $(this).attr('href')+' #content'; 

    $('#content').hide('fast',loadContent); 
    $('#load').remove();   
    $('#wrapper').append('<span id="load">LOADING...</span>'); 
    $('#load').fadeIn('normal');   
    window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-3);  

    function loadContent() { 
     $('#content').load(toLoad,'',showNewContent()); 

    } 
    function showNewContent() { 
     $('#content').show('normal',hideLoader()); 
    } 
    function hideLoader() { 
     $('#load').fadeOut('normal'); 
    } 
    return false; 
}); 

此功能在$(文件)。就绪(),现在我需要在下方新增功能,使图像动态加载成为收藏的一部分。

$('.gallery a').lightBox({txtImage: 'Design'}) 

什么我做的是...调用文件portfolio.php并采取#内容DIV中的HTML和在用户正在浏览的网页#内容股利加载它。

如果可能请帮助代码。

回答

1

这里假设.gallery#content这里的孩子。你将它添加到showNewContent()功能,像这样:

function loadContent() { 
    $('#content').load(toLoad,'',showNewContent); 

} 
function showNewContent() { 
    $('#content').find('.gallery a').lightBox({txtImage: 'Design'}) 
       .end().show('normal',hideLoader); 
} 
function hideLoader() { 
    $('#load').fadeOut('normal'); 
} 

确保调用showNewContent的回调,而不是showNewContent(),(没有括号!),否则它实际上执行该功能权限,然后并试图分配结果到回调函数,而不是函数本身,所以当动画完成时不运行它。

+0

谢谢尼克......它的工作! – Masade 2010-06-25 14:50:40