我有以下結構的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'] *」),它似乎沒有找到任何圖像,所以過濾器返回一個空列表。 –