gpt4 book ai didi

javascript - fancybox v2 iframe 高度调整

转载 作者:行者123 更新时间:2023-11-30 17:31:46 24 4
gpt4 key购买 nike

有没有办法让下面的脚本只适用于 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");
};
}
});

JSFIDDLE


你也可以像 this.element 这样引用 $(this)

$(".fancybox").fancybox({
afterLoad: function () {
if (this.type == "iframe") {
this.width = this.element.data("width");
this.height = this.element.data("height");
};
}
});

JSFIDDLE

关于javascript - fancybox v2 iframe 高度调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22902092/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com