我有以下结构的DOM元素:借助Uranium.io的缩放交互功能,放大/缩小按钮需要什么来查找要放大/缩小的图像?
<div class="flexslider" data-ur-set="zoom">
<div data-ur-zoom-component="loading" data-ur-state="disabled">Loading…</div>
<div data-ur-zoom-component="button" data-ur-state="disabled">
<span>+</span><span>−</span>
</div>
<ul class="slides" data-ur-zoom-component="view_container">
<li><img src="//mydomain.com/path/to/small/image" onerror="this.src=altView.src" class="thumbnail selected-thumbnail" data-ur-src="//mydomain.com/path/to/large/image" data-ur-zoom-component="img"></li>
<li><img src="//mydomain.com/path/to/small/image" onerror="this.src=altView.src" class="thumbnail" data-ur-src="//mydomain.com/path/to/large/image" data-ur-zoom-component="img"></li>
<li><img src="//mydomain.com/path/to/small/image" onerror="this.src=altView.src" class="thumbnail" data-ur-src="//mydomain.com/path/to/large/image" data-ur-zoom-component="img"></li>
</ul>
</div>
当我点击图像本身(一个用于当前显示的幻灯片)/缩小工程变焦。然而,当我点击我看到一个错误在JavaScript控制台中的形象,说TypeError: $img.data(...) is null
function setActive(img) {
if ($img && img != $img[0]) {
self.state = "enabled-out";
var zoomImg = $img.data("urZoomImg");
zoomImg.transform(0, 0, 1);
zoomImg.transitionEnd();
}
$img = $(img);
}
// zoom in/out button, zooms in to the center of the image
$(self.button).on(touchscreen ? "touchstart.ur.zoom" : "click.ur.zoom", function() {
if (self.img.length > 1)
setActive($(self.img).filter($container.find("[data-ur-state='active'] *"))[0]);
else
setActive(self.img[0]);
$img.data("urZoomImg").zoom(); // <---- This is the line throwing the error
});
我已表明如该null
类型错误的代码中引发上述的+
按钮跨度。我跟踪它,发现setActive正在发送一个undefined
img参数。
我怀疑我没有得到铀缩放交互的数据属性正确,但为什么+
按钮会抛出这个错误?
正确的行为就像是在这里的例子:http://uranium.io/interactions/zoom.html
你好萨加尔。目前我正在逐步使用断点并观察Firebug中的表达式。我正在看$ $ container.find(“[data-ur-state ='active'] *”),它似乎没有找到任何图像,所以过滤器返回一个空列表。 –