简体   繁体   English

一页上有多个 panzoom

[英]multiple panzoom's on one page

I'm using this panzoom library , however I'm struggling to get it to work multiple instances on the same page with custom options.我正在使用这个panzoom 库,但是我正在努力让它使用自定义选项在同一页面上工作多个实例。

Here is a jsFiddle which allows for multiple panzooms all with the same class.这是一个jsFiddle ,它允许使用同一个类进行多个 panzoom。

 const paths = document.querySelectorAll('.content-image-module .image-pinch img') paths.forEach(Panzoom)
 .image-pinch { min-height: 360px; height: 100%; max-height: 414px; width: 100%; overflow: hidden; background: red z-index: 9999; position: relative; } img { width: initial; max-width: 2000px; position: initial; -webkit-transform: initial; -ms-transform: initial; transform: initial; max-width: initial; cursor: crosshair; }
 <script src="https://cdn.jsdelivr.net/npm/@panzoom/panzoom@4.4.1/dist/panzoom.min.js"></script> <section class="content-image-module"> <div class="image-pinch"> <img src="https://images.unsplash.com/photo-1622495505508-03991221aca7?ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1934&q=80"/> </div> </section> <section class="content-image-module"> <div class="image-pinch"> <img src="https://images.unsplash.com/photo-1622495505508-03991221aca7?ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1934&q=80"/> </div> </section> <section class="content-image-module"> <div class="image-pinch"> <img src="https://images.unsplash.com/photo-1622495505508-03991221aca7?ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1934&q=80"/> </div> </section>

However I can't figure out how to add any custom options to it?但是我不知道如何向它添加任何自定义选项?

Here is a jsFiddle , which has my custom options, but I can't get it to work alongside the forEach and work with multiple instances with the same class on the same page.这是一个jsFiddle ,它有我的自定义选项,但我无法让它与forEach一起工作并在同一页面上使用相同类的多个实例。 You can see in the fiddle how only the first one works.您可以在小提琴中看到只有第一个是如何工作的。

 const elem = document.querySelector('.content-image-module .image-pinch img') const panzoom = Panzoom(elem, { maxScale: 5, minScale: 1, maxScale: 3, contain: 'outside', disableZoom: false, })
 .image-pinch { min-height: 360px; height: 100%; max-height: 414px; width: 100%; overflow: hidden; background: red z-index: 9999; position: relative; } img { width: initial; max-width: 2000px; position: initial; -webkit-transform: initial; -ms-transform: initial; transform: initial; max-width: initial; cursor: crosshair; }
 <script src="https://cdn.jsdelivr.net/npm/@panzoom/panzoom@4.4.1/dist/panzoom.min.js"></script> <section class="content-image-module"> <div class="image-pinch"> <img src="https://images.unsplash.com/photo-1622495505508-03991221aca7?ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1934&q=80"/> </div> </section> <section class="content-image-module"> <div class="image-pinch"> <img src="https://images.unsplash.com/photo-1622495505508-03991221aca7?ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1934&q=80"/> </div> </section> <section class="content-image-module"> <div class="image-pinch"> <img src="https://images.unsplash.com/photo-1622495505508-03991221aca7?ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1934&q=80"/> </div> </section>

I managed to fix my issue with the below:我设法解决了以下问题:

const paths = document.querySelectorAll('.content-image-module .image-pinch img')
paths.forEach((elem) => {
    const panzoom = Panzoom(elem, {
        maxScale: 5,
        minScale: 1,
        maxScale: 3,
        contain: 'outside',
        disableZoom: false
    });
});

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

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