有没有办法让下面的脚本只适用于 fancybox 中的 iframe?我有一个包含图库和 iframe 的页面。我希望 iframe 具有不同的高度而不影响图像大小。
$('.fancybox').fancybox({
afterLoad: function () {
this.width = $(this.element).data("width");
this.height = $(this.element).data("height");
}
});
最佳答案
在将 data-*
值传递给 fancybox 之前,您可以设置一个条件来验证内容的 type
,例如:
$(".fancybox").fancybox({
afterLoad: function () {
if (this.type == "iframe") {
this.width = $(this.element).data("width");
this.height = $(this.element).data("height");
};
}
});
你也可以像 this.element
这样引用 $(this)
$(".fancybox").fancybox({
afterLoad: function () {
if (this.type == "iframe") {
this.width = this.element.data("width");
this.height = this.element.data("height");
};
}
});
关于javascript - fancybox v2 iframe 高度调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22902092/