[英]On Click show lightbox
I am using Simple Lightbox ( http://simplelightbox.com ) and have it all working, however I want to have a link that loads the lightbox and first image, instead of always having to click the images themselves. 我正在使用简单灯箱( http://simplelightbox.com )并能正常工作,但是我想要一个链接来加载灯箱和第一张图片,而不必总是单击图片本身。
I have tried this but it's not working. 我已经尝试过了,但是没有用。
$(".launch-gallery").click(function () {
lightbox.show();
});
Put the script tag at the end of the body tag; 将script标签放在body标签的末尾;
<html>
<body>
<script src="lightbox.js"></script>
<script>
$(".launch-gallery").click(function () {
lightbox.show();
});
</script>
</body>
</html>
if the button with class launch gallery is dynamically added to the page or not rendered by the server, bind the click event to the document; 如果带有启动库类的按钮被动态添加到页面或服务器未呈现,则将click事件绑定到文档;
<html>
<body>
<script src="lightbox.js"></script>
<script>
$(document).on("click",".launch-gallery",function () {
lightbox.show();
});
</script>
</body>
</html>
Make sure also that the button has the class "launch-gallery"; 确保按钮具有“ launch-gallery”类。
<button class='launch-gallery'>Launch</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.