我已经查看了所有示例,包括 https://simplelightbox.com/ 上的示例,但我似乎陷入困境,想知道是否还有其他我错过的事情发生。 我直接使用示例中的以下代码初始化一个 simpleLightbox。
var gallery = $('.gallery a').simpleLightbox();
当我点击画廊 a.link 时,它工作正常。 我试图触发这个画廊从一个独立的按钮打开,上面写着“查看画廊”它有一个名为 .view-gallery 的类。它具有以下与其关联的点击内容。
$(document).on('click', '.view-gallery', function (event) {
gallery.open();
})
同样,这直接来自 simplelightbox 的示例。 我知道点击事件被触发,因为我可以在其中console.log一些垃圾并返回。单击时出现以下错误:
Uncaught TypeError: gallery.open is not a function
<anonymous> https://*/wp-content/themes/wilhelm/js/main.js?ver=1719958181:84
jQuery 10
<anonymous> https://*/wp-content/themes/wilhelm/inc/assets/js/bootstrap.min.js?ver=6.5.5:6
<anonymous> https://*/wp-content/themes/wilhelm/inc/assets/js/bootstrap.min.js?ver=6.5.5:6
<anonymous> https://*/wp-content/themes/wilhelm/inc/assets/js/bootstrap.min.js?ver=6.5.5:6
来自文档:open——使用给定元素打开灯箱 为什么这么难?
我使用的是没有定义 open 函数的旧版本。我从 GitHub 加载了最新版本,它成功了。