【发布时间】:2021-02-20 09:06:35
【问题描述】:
最近几天我一直在编写这段代码,目标是制作一个完整的 .div 打开元素内的链接。现在我想做的是将此href提供给featherlightbox,以便它可以打开它。如果您认为有比featherlightbox更简单或更好的东西,请随时向我提出建议。
代码(尚未工作)是:
$('.o-neuron-hover a').on('click', function(e) {
e.preventDefault(); // stop link
$("#myDiv").load(this.href, function() {
$.featherLight("#myDiv")
});
关于羽毛灯箱偶数的文档是:
Bind Featherlight
You can bind the Featherlight events on any element using the following code:
$('.myElement').featherlight($content, configuration);
It will then look for the targetAttr (by default "data-featherlight")
on this element and use its value to find the content that will be opened
as lightbox when you click on the element.
您知道如何将这两个元素合并在一起,以便任何链接都可以在灯箱中打开吗?抱歉,这是我接触 JQUERY 的第一天。谢谢。
【问题讨论】:
-
$('.o-neuron-hover a').on('click',表示容器内带有class="o-neuron-hover"的任何链接都可以使用。由于您无法通过显示minimal reproducible example 来帮助我们,因此您得到了您所得到的。如果 .o-neuron-hover 未指向链接容器,请将其更改为可以指向的内容。如果链接有类,则更改为 $('a.o-neuron-hover').on('click',`。我会帮助你更多,但你没有发布任何 HTML
标签: jquery wordpress featherlight.js