【问题标题】:implement zoom in zoom out and drag able JQuery实现放大缩小和拖动能够JQuery
【发布时间】:2020-07-27 14:12:25
【问题描述】:

我用jQuery实现了放大和缩小,问题是用户可以在div中拖动图像,从而在图像和div之间创建一个空间 我希望图像的角落不在 div 内,但能够在 div 之外 我想实现类似this 这是my project

我使用this 插件来放大缩小

我的html代码:

 <div style="background-color: white; border : 1px solid #d6d6d6ee; margin: 1rem; width: fit-content;">
      <div class="zoom--actions" style="margin: 5px;">
          <a id="zoom-in"><img style="width: 25px; cursor: pointer;" src="zoomIn.png" /></a>
        <a id="zoom-out"><img style="width: 25px; cursor: pointer;" src="zoomOut.png" /></a>
        <a id="reset"><img style="width: 25px; cursor: pointer;" src="reset.png" /></a>
      </div>
      <div id="zoom-box" class="parent" style="background-color: antiquewhite; overflow: hidden;">
          <div class="panzoom" id="panzoom-element">
              <img id="main-image" class="product-main-image mb-3" src="images/1.jpg">
          </div>
      </div>
  </div>

默认选项:

 var defaultOptions = {
        animate: false,
        canvas: false,
        cursor: 'move',
        disablePan: false,
        disableZoom: false,
        disableXAxis: false,
        disableYAxis: false,
        duration: 200,
        easing: 'ease-in-out',
        exclude: [],
        excludeClass: 'panzoom-exclude',
        handleStartEvent: function (e) {
            e.preventDefault();
            e.stopPropagation();
        },
        maxScale: 4,
        minScale: 1,
        overflow: 'hidden',
        panOnlyWhenZoomed: false,
        relative: false,
        setTransform: setTransform,
        startX: 0,
        startY: 0,
        startScale: 1,
        step: 0.5,
        touchAction: 'none'
    };

谢谢

【问题讨论】:

    标签: javascript html jquery css


    【解决方案1】:

    图片上有mb-3。这可能是在图像上添加空白的原因。您应该将mb-3 添加到图像的容器中,而不是图像本身。

    编辑:你可以试试;

     var defaultOptions = {
            animate: false,
            canvas: false,
            cursor: 'move',
            contain: 'outside',
            disablePan: false,
            disableZoom: false,
            disableXAxis: false,
            disableYAxis: false,
            duration: 200,
            easing: 'ease-in-out',
            exclude: [],
            excludeClass: 'panzoom-exclude',
            handleStartEvent: function (e) {
                e.preventDefault();
                e.stopPropagation();
            },
            maxScale: 4,
            minScale: 1,
            overflow: 'hidden',
            panOnlyWhenZoomed: false,
            relative: false,
            setTransform: setTransform,
            startX: 0,
            startY: 0,
            startScale: 1,
            step: 0.5,
            touchAction: 'none'
        };
    

    【讨论】:

    • 感谢您的回复,但我的问题是用户可以将图像拖到 div 中
    • 检查文档 - 将设置 contain 更改为 inside。默认情况下,contain 在脚本上设置为 null。这将防止图像被拖出容器。
    • 还要确保将overflow 设置为hidden。它不是你使用的最好的小插件,所以尝试一下选项或找到另一个小插件:)
    • 感谢 Dexterians,溢出设置为隐藏,并且在脚本文件中无法更改包含值我更新了我的帖子并添加了 defaultOptions
    • 您自己添加选项。即contain: 'inside',
    猜你喜欢
    • 1970-01-01
    • 2012-04-30
    • 1970-01-01
    • 1970-01-01
    • 2021-01-26
    • 2018-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多