使用javascript触发灯箱 [英] Trigger lightbox with javascript

查看:76
本文介绍了使用javascript触发灯箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用此库: http://lokeshdhakar.com/projects/lightbox2/

我无法将 rel =lightbox附加到每个图像,所以我想使用jQuery来触发灯箱。

I can't attach rel="lightbox" to each image so I want to use jQuery to trigger the lightbox.

我在考虑类似的事情:

$('img').click(function(){
  //triger lightbox for this image
  //use self src as href
});

如何为一张图片触发灯箱?

How can I trigger the lightbox for one image?

推荐答案

通过在 a img 标记来解决问题>标记和触发点击之后。

Solved the problem by wrapping the img tag in an a tag and triggering click on a after that.

$('img').click(function () {
    $(this).wrap('<a href="' + $(this).attr("src") + '" rel="lightbox" />');
    $(this).parent('a').trigger('click');
});

这篇关于使用javascript触发灯箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆