admin管理员组文章数量:1414604
I m using shadowbox.js for image gallery display.
for this we have to generate html like this
<a href="images/Ganesha3602.jpg" rel="shadowbox[my]"><img src="images/thumb.jpg" alt="First" title="First image" /></a>
<a href="images/original.jpg" rel="shadow[my]"><img src="images/thumb.jpg" alt="Second" title="Second image" /></a>
<a href="images/original.jpg" rel="shadowbox[my]"><img src="images/thumb.jpg" alt="First" title="First image" /></a>
and then apply Shadowbox.init()
on body load. Its working like a charm when the above html is static. But when i generate it dynamically using $.ajax
and call Shadowbox.init()
on success; shadowbox does not work. I also tried calling Shadowbox.init()
on plete.
My code is something like this:
$(document).on('click','#load_posts_ments',function(){
$.ajax({
url:"post_ment_json.php",
type: "POST",
dataType: "json",
data:{user_id:"123"},
success: function(data){
load_posts_ments(data);
},
plete: function(){
Shadowbox.init();
}
});
});
Where am I going wrong? I looked the shadowbox website but there was no documentation regarding dynamically loaded content. Help would be appreciated.
I m using shadowbox.js for image gallery display.
for this we have to generate html like this
<a href="images/Ganesha3602.jpg" rel="shadowbox[my]"><img src="images/thumb.jpg" alt="First" title="First image" /></a>
<a href="images/original.jpg" rel="shadow[my]"><img src="images/thumb.jpg" alt="Second" title="Second image" /></a>
<a href="images/original.jpg" rel="shadowbox[my]"><img src="images/thumb.jpg" alt="First" title="First image" /></a>
and then apply Shadowbox.init()
on body load. Its working like a charm when the above html is static. But when i generate it dynamically using $.ajax
and call Shadowbox.init()
on success; shadowbox does not work. I also tried calling Shadowbox.init()
on plete.
My code is something like this:
$(document).on('click','#load_posts_ments',function(){
$.ajax({
url:"post_ment_json.php",
type: "POST",
dataType: "json",
data:{user_id:"123"},
success: function(data){
load_posts_ments(data);
},
plete: function(){
Shadowbox.init();
}
});
});
Where am I going wrong? I looked the shadowbox website but there was no documentation regarding dynamically loaded content. Help would be appreciated.
Share Improve this question edited Jul 10, 2012 at 9:16 Daedalus 7,7225 gold badges38 silver badges63 bronze badges asked Jul 10, 2012 at 8:01 BhoopeshBhoopesh 4001 gold badge3 silver badges13 bronze badges 4- yeah I had tried that too but it did not work – Bhoopesh Commented Jul 10, 2012 at 8:06
- 1 Could this answer help you? stackoverflow./questions/9144577/… – Niklas Commented Jul 10, 2012 at 8:20
- @Niklas thanks man .. You saved my day. :) using this code worked Shadowbox.clearCache(); Shadowbox.setup(); – Bhoopesh Commented Jul 10, 2012 at 8:30
- I've posted an answer in case they don't close this as a duplicate =) – Niklas Commented Jul 10, 2012 at 8:41
1 Answer
Reset to default 6You need to reinitialize it by using Shadowbox.clearCache();
and Shadowbox.setup();
.
It's been explained much better here: shadowbox stops working after jquery function call
本文标签: javascriptApplying Shadowboxjs on dynamically generated contentStack Overflow
版权声明:本文标题:javascript - Applying Shadowbox.js on dynamically generated content - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745193786a2647038.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论