我目前有以下代码将灯箱添加到具有rel="facebox"链接。
$(document).ready(function() { $('a[rel*=facebox]').facebox(); });这很有效,直到页面加载时间太长。
如何在文档加载之前应用此功能? 理想情况下,我想首先调用.facebox()函数,当DOM加载时,它会搜索任何带有rel="facebox"链接并应用该函数。
有点像.on()函数,但没有事件。
那有意义吗? 提前致谢!
I currently have the following code to add a lightbox to links that have rel="facebox".
$(document).ready(function() { $('a[rel*=facebox]').facebox(); });This works well until a page takes a little too long to load.
How do I apply this before the document has loaded? Ideally I'd like to call the .facebox() function first and as the DOM loads, it searches for any link with rel="facebox" and applies the function.
Kind of like the .on() function but without an event.
Does that make sense? Thanks in advance!
最满意答案
这里有几个链接可能有助于解决这个问题......
在DOM准备好之前使用元素并使用JavaScript检测DOM节点插入...
Found my solution by doing the following:
$(document).on('click', 'a[rel*=facebox]', function() { $.facebox({ ajax: $(this).attr('href') }); return false; });Hope that helps somebody.
更多推荐
发布评论