JavaScript 中的 Rel 属性
我有灯箱画廊视图脚本并且工作正常。
在我的网站中,我使用 ajax 脚本调用另一个页面并将其加载到 DIV 中,
例如:
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('loadmailfunctions');
ajaxDisplay.innerHTML = ajaxRequest.responseText; sizeit();
setVisibility('uploads', 'block'); settotime();
}
}
ajaxRequest.open("GET", "profile/photos.inc.php", true);
ajaxRequest.send(null);
然后加载我需要的所有照片,但是当我单击照片并使用 rel="lightbox" 时,它不起作用。
这是否与父 DOM/窗口有关?抱歉,我是个菜鸟,但我希望有人能指出我正确的方向?
编辑:
在加载的页面 profile/photos.inc.php 中,我有以下代码:
echo '<li><a href="',$row['localdirectory'],$row['photo'],'" rel="lightbox" ><img src="',$row['localdirectory'],$row['photo'],'" style="width:110px; height:85px;" alt="" /></a></li>'
但不执行 Lightbox 查看器脚本。
I have the lightbox gallery view script and is working fine.
In my site I use an ajax script to call another page and load it into a DIV
For Example:
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('loadmailfunctions');
ajaxDisplay.innerHTML = ajaxRequest.responseText; sizeit();
setVisibility('uploads', 'block'); settotime();
}
}
ajaxRequest.open("GET", "profile/photos.inc.php", true);
ajaxRequest.send(null);
This then loads all the photos I need but when I click on a photo and use the rel="lightbox" it does not work.
Is this something to do with the parent DOM / window or something? Sorry bit of a noob, but I was hoping someone could point me in the right direction?
EDIT:
In the loaded page profile/photos.inc.php, I have this code:
echo '<li><a href="',$row['localdirectory'],$row['photo'],'" rel="lightbox" ><img src="',$row['localdirectory'],$row['photo'],'" style="width:110px; height:85px;" alt="" /></a></li>'
But does not execute the Lighbox viewer script.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Lightbox 在页面加载后激活,它扫描 DOM 树,搜索具有
rel="lightbox"
属性的锚点,并将onclick
事件绑定到它们。当您执行 AJAX 调用时,新元素会添加到 DOM 树中,但您必须手动初始化扫描新锚点。Lightbox activates after page load, it scans DOM tree searching for anchors with
rel="lightbox"
attribute and bindsonclick
event to them. When you perform AJAX call, new elements are added to DOM tree, but you have to manually initialize scanning for new anchors.正如 dev-null-dweller 所暗示的,Lightbox 使用示例仅在页面加载时激活
rel="lightbox"
链接:您应该为神奇地出现在
div 中的新元素重新运行此示例
after Ajaxifying:顺便说一句,如果您正在使用 lightbox jQuery 插件(我必须假设您是这样,因为您没有另外指定),为什么您不整体使用 jQuery?
如果您不使用 jQuery 插件,则以类似的方式重复您的事件处理程序设置。
As dev-null-dweller implied, the Lightbox usage example only activates
rel="lightbox"
links on page load:You should re-run this for new elements that have magically appeared in your
div
after Ajaxifying:Incidentally, if you're using the lightbox jQuery plugin (and I have to assume that you are, since you haven't specified otherwise), why aren't you using jQuery as a whole?
If you're not using the jQuery plugin, then repeat your event handler setup in a similar way.