我很抱歉不知道如何问这个问题,但是,就这样吧。
我有一个图像滑块,它只在需要时加载图像,所以当页面加载时它们并不都存在于 dom 中。话虽如此,我需要编写一个条件来显示基于某个图像何时在页面上可见的元素。问题是由于加载页面时 DOM 中不存在照片,所以我无法使用 jQuery 来为我处理这个问题。有谁知道我需要做什么才能完成这项工作?
这是html,我试图在其中监听 <img src="http://example.com/images/HOME_PAGE/1.jpg">
以加载:
<div class="galleria-images" style="position: relative; top: 0px; left: 0px; width: 100%; height: 100%;">
<div class="galleria-image" style="overflow: hidden; position: absolute; top: 0px; left: 0px; opacity: 0; -webkit-transition: none; transition: none; z-index: 0; width: 1038px; height: 575px;">
<div class="galleria-layer" style="position: absolute; top: 0px; left: 0px; right: 0px; bottom: 0px; z-index: 2; display: none;"></div>
<img src="http://example.com/images/HOME_PAGE/2.jpg" style="display: block; opacity: 1; min-width: 0px; min-height: 0px; max-width: none; max-height: none; width: 1038px; height: 583px; position: absolute; top: -4px; left: 0px;" width="1038" height="583">
</div>
<div class="galleria-image" style="overflow: hidden; position: absolute; top: 0px; left: 0px; opacity: 1; width: 1038px; height: 575px; -webkit-transition: none; transition: none; z-index: 1;">
<div class="galleria-layer" style="position: absolute; top: 0px; left: 0px; right: 0px; bottom: 0px; z-index: 2; display: none;"></div>
<img src="http://example.com/images/HOME_PAGE/1.jpg" style="display: block; opacity: 1; min-width: 0px; min-height: 0px; max-width: none; max-height: none; width: 1038px; height: 583px; position: absolute; top: 0px; left: 0px;" width="1038" height="583">
</div>
</div>
一旦看到加载的图像,我就尝试使用 jQuery 添加“播放按钮”叠加层,但显然我遇到了麻烦,因为每个图像都是在页面加载后加载的。
这是加载图像的JS:
(function (a) {
Galleria.addTheme({
name: "classic",
author: "Galleria",
css: "galleria.classic.css",
defaults: {
transition: "slide",
thumbCrop: "height",
_toggleInfo: !0
},
init: function (b) {
Galleria.requires(1.25, "This version of Classic theme requires Galleria 1.2.5 or later"), this.addElement("info-link", "info-close"), this.append({
info: ["info-link", "info-close"]
});
var c = this.$("info-link,info-close,info-text"),
d = Galleria.TOUCH,
e = d ? "touchstart" : "click";
this.$("loader,counter").show().css("opacity", .4), d || (this.addIdleState(this.get("image-nav-left"), {
left: -50
}), this.addIdleState(this.get("image-nav-right"), {
right: -50
}), this.addIdleState(this.get("counter"), {
opacity: 0
})), b._toggleInfo === !0 ? c.bind(e, function () {
c.toggle()
}) : (c.show(), this.$("info-link, info-close").hide()), this.bind("thumbnail", function (b) {
d ? a(b.thumbTarget).css("opacity", this.getIndex() ? 1 : .6) : (a(b.thumbTarget).css("opacity", .6).parent().hover(function () {
a(this).not(".active").children().stop().fadeTo(100, 1)
}, function () {
a(this).not(".active").children().stop().fadeTo(400, .6)
}), b.index === this.getIndex() && a(b.thumbTarget).css("opacity", 1))
}), this.bind("loadstart", function (b) {
b.cached || this.$("loader").show().fadeTo(200, .4), this.$("info").toggle(this.hasInfo()), a(b.thumbTarget).css("opacity", 1).parent().siblings().children().css("opacity", .6)
}), this.bind("loadfinish", function (a) {
this.$("loader").fadeOut(200)
})
}
})
})(jQuery);
提前致谢!