使用新创建的锚元素触发事件
我在 jquery 中使用 fancybox lightbox 插件。它挂钩到锚标记,以便以下拉出与 rel =“example_group”引用的其他图像链接的图像:
<script type="text/javascript">
$(document).ready(function() {
$("a[rel=example_group]").fancybox();
});
</script>
<body>
<a rel="example_group" href="./example/7_b.jpg"><img alt="" src="./example/7_s.jpg" /></a>
<a rel="example_group" href="./example/9_b.jpg"><img alt="" src="./example/9_s.jpg" /></a>
</body>
我想将其他图像添加到弹出图库,但我不想包含它们在点击链接之前的页面上。现在,正在显示两个图像,然后将其链接起来。例如,我想挂钩第三个图像,而不将其显式显示在正文中。
我尝试了以下操作:
<script type="text/javascript">
$(document).ready(function() {
$("a[rel=example_group]").fancybox();
$("<a rel='example_group' href='./example/8_b.jpg'><img src='./example/8_s.jpg' /></a>").appendTo("body");
});
</script>
这会将第三张图像挂入图库,但也会在正文中显示该图像。所以我对appendTo部分尝试了同样的操作:
<script type="text/javascript">
$(document).ready(function() {
$("a[rel=example_group]").fancybox();
$("<a rel='example_group' href='./example/8_b.jpg'><img src='./example/8_s.jpg' /></a>");
});
</script>
但是这个添加的元素似乎与rel组没有关联,并且只有两个图像链接在一起。
如何添加新的锚元素并将其挂钩到 .fancybox 调用,而无需将引用附加到正文?我认为这个问题与特定的 fancybox 代码足够独立。这似乎只是一个足够的 jquery 专业知识的问题。
I'm using the fancybox lightbox plugin in jquery. It hooks into anchor tags such that the following pulls up an image that is chained with the other images referenced with rel = "example_group":
<script type="text/javascript">
$(document).ready(function() {
$("a[rel=example_group]").fancybox();
});
</script>
<body>
<a rel="example_group" href="./example/7_b.jpg"><img alt="" src="./example/7_s.jpg" /></a>
<a rel="example_group" href="./example/9_b.jpg"><img alt="" src="./example/9_s.jpg" /></a>
</body>
I'd like to add additional images to the pop-up gallery but I do not want to include them on the page before a link is hit. So right now, two images are being displayed and are then linked. I would like to, for example, hook in a third image without explicitly displaying it in the body.
I attempted the following:
<script type="text/javascript">
$(document).ready(function() {
$("a[rel=example_group]").fancybox();
$("<a rel='example_group' href='./example/8_b.jpg'><img src='./example/8_s.jpg' /></a>").appendTo("body");
});
</script>
This will hook a third image into the gallery, but also displays the image in the body. So I tried the same thing with the appendTo portion:
<script type="text/javascript">
$(document).ready(function() {
$("a[rel=example_group]").fancybox();
$("<a rel='example_group' href='./example/8_b.jpg'><img src='./example/8_s.jpg' /></a>");
});
</script>
But this added element doesn't seem to associate with the rel group, and only two images are chained together.
How can I add a new anchor element and hook it to the .fancybox call without having to append the reference to the body? I assume this question is independent enough of the specific fancybox code. It seems just a matter of sufficient jquery expertise.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对
.fancybox()
不太了解,但这里有一个您可以尝试的想法。将不想在页面上显示的图像放置在隐藏的容器中。它们在页面上不可见,但我想它们会在 fancybox 中。
HTML
在 jQuery 中,将图像附加到该容器。
I don't really know much about
.fancybox()
, but here's an idea you might try.Place the images that you don't want displayed on the page in a container that is hidden. They won't be visible on the page, but I would imagine they would be in the fancybox.
HTML
In jQuery, append the image to that container.