开发者

Shadowbox doesn't works when it's placed inside of a jQuery ".html" function

Well, I'm placing a link inside of a div called "alerta" with jQuery 开发者_StackOverflow中文版function ".html".

Ok, then I tried to place the "rel='shadowbox'" parameter inside of my "a" tag and it doesn't works.

$('#alerta').html('<a href="selecao.php?id=' + 
                    avisos[i+1] + '" rel="shadowbox">' + avisos[i] + '</a>');

If the link is placed directly on the page, it works fine...

Thanks.


Shadowbox initialises the elements that have a rel of shadowbox on page load. If you use jquery to add a link then the link won't have an event handler attached to it.

Try adding a class to the link, such as sbox. Then put this in your script tags instead of Shadowbox.init();

window.onload = function() {
   Shadowbox.setup($('.sbox'));
};

Shadowbox.init({
     skipSetup:true, // skip the automatic setup    
});

$(document).ready(function(){

       $('a.sbox').live('click',function(event){

       Shadowbox.open(this);
       //Stops loading link
       event.preventDefault();

       });
});


I suppose you need to call the

Shadowbox.init();

or somethink similar to make shadowbox aware of the newly added links.

UPDATE see the answer form Lance May. Mine is obsolete.


Have a look at the following SO post. It may help.

jQuery - Shadowbox rebinding


I Solved the problem. You have to initialize

(shadowbox.ini()) 

just when all the "shadowbox links" are placed.

Thank you for the support.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜