繁体   English   中英

通过Uranium.io的缩放交互,“放大/缩小”按钮查找要放大/缩小的图像需要什么?

[英]With Uranium.io's zoom interaction, what is required for the zoom in/out buttons to find the image to zoom in/out from?

我具有以下结构的DOM元素:

<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 TypeError的地方。 我跟踪了它,发现setActive正在发送一个undefined img参数。

我怀疑我尚未获得Uranium Zoom交互的数据属性正确,但是为什么+按钮会引发此错误?

正确的行为类似于此处的示例: http : //uranium.io/interactions/zoom.html

对于那些发现自己处于我位置的人,我发现了正在发生的事情,这使我了解如何为自己解决问题。

如果滑块中有多个图像,则Uranium缩放期望将它们排列在Uranium传送带中。 轮播DOM结构意味着包含每个图像的元素将具有data-ur-state='active' ,因此选择器$container.find("[data-ur-state='active'] *")将找到该图像在当前显示的幻灯片元素中。

但是,如果您不使用轮播,则可能会看到我看到的null TypeError。 要在不使用Uranium轮播的情况下解决此问题,有一种方法可以更改您的核心Uranium文件,以捕获适合您项目的选择器。 但是,您正在更改核心文件,因此请当心!

要更改的文件命名为assets/javascript/.remote/http__colon____slash____slash__downloads.moovweb.com__slash__uranium__slash__1.0.167__slash__uranium-pretty.js

在第608行修改选择器(如果您使用的是类似的Uranium版本,则代码块如下所示)。

605     // zoom in/out button, zooms in to the center of the image
606     $(self.button).on(touchscreen ? "touchstart.ur.zoom" : "click.ur.zoom", function() {
607       if (self.img.length > 1)
608         setActive($(self.img).filter($container.find("[data-ur-state='active'] *"))[0]);
609       else
610         setActive(self.img[0]);
611       $img.data("urZoomImg").zoom();
612     });

重新启动moov服务器,使其生成新的assets/javascript/main.js并且您的缩放按钮将使用新代码并开始工作!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM