jquery panzoom js 有问题,增量值在调用 destroy 时不会被销毁

Having issues with jquery panzoom js, increment value is not destroyed upon calling destroy

我在处理 jquery.panzoom.js

时遇到问题

我的要求是点击一个按钮允许多次放大图像。 我有一个缩放按钮的原因是,我还有一个平移按钮,所以我必须单击它们并且在鼠标滚轮上我必须相应地处理平移或缩放。

我的问题是,即使在调用 destroy() 方法之后,increment 参数也会增加 current + previous 增量,这使得缩放增加超过 0.1,尽管每次都设置该参数。

它增加了:

transform : matrix(0.1, 0, 0, 0.1, 0, 0)
transform : matrix(0.2, 0, 0, 0.2, 0, 0)

再次单击缩放按钮后,

transform : matrix(0.4, 0, 0, 0.4, 0, 0)
transform : matrix(0.6, 0, 0, 0.6, 0, 0)

再次单击缩放按钮后,

transform : matrix(0.9, 0, 0, 0.9, 0, 0)
transform : matrix(1.2, 0, 0, 1.2, 0, 0)

我知道最直接的问题是为什么我要一次又一次地点击它们? 答案是因为我需要对图像做一些其他操作,比如添加矩形或圆形等。

我的代码:

$section.panzoom("destroy"); 
         $section.panzoom(
         {
              disablePan: disablePan,
              increment: 0.1,
              minScale: 0.1,
              maxScale: 50,
              $reset: $("#resetImg")
         });
         $section.on('mousewheel', function( e ) {
             e.preventDefault();
                var delta = e.delta || e.originalEvent.wheelDelta;
                var zoomOut = delta ? delta < 0 : e.originalEvent.deltaY > 0;
                if(UIConstants.zoomActivated == true) {
                     $section.panzoom('zoom', zoomOut, {
                         increment: 0.1,
                         animate: false,
                         focal: e
                    });
                } else {
                     $section.panzoom('zoom', zoomOut, {
                      increment: 0.1,
                      animate: false,
                      focal: e
                    });
                }
          });

检查 JQueryUI https://jqueryui.com/draggable/ 以获得拖动的灵活性。 您可以在那里尝试示例。

为了缩放,最好保留一个标志变量,而不是每次都触发事件。