平移缩放 JQuery 功能

Pan Zoom JQuery functionality

本文关键字:功能 JQuery 缩放      更新时间:2023-09-26

HTML 和 Javascript

<section>
     <h1>Panning and zooming with CSS3</h1>
    <div class="parent">
        <div class="panzoom">
            <img src="image1" width="400" height="400">
        </div>
    </div>
    <div class="buttons">
        <button class="zoom-in">Zoom In</button>
        <button class="zoom-out">Zoom Out</button>
        <input type="range" class="zoom-range">
        <button class="reset">Reset</button>
    </div>
    <script>
        (function() {
            var $section = $('section').first();
            $section.find('.panzoom').panzoom({
                $zoomIn: $section.find(".zoom-in"),
                $zoomOut: $section.find(".zoom-out"),
                $zoomRange: $section.find(".zoom-range"),
                $reset: $section.find(".reset")
            });
        })();
    </script>
</section>

我正在使用平移缩放插件。

https://github.com/timmywil/jquery.panzoom

如何限制缩小功能。我的意思是我想将图像缩小到图像的特定大小,例如 100 像素。

演示http://timmywil.github.io/jquery.panzoom/demo/#inverted-contain

我试过Inverted containment within the parent element (to hide what's behind) 从演示。但对我来说它不起作用。请帮忙。

我知道

这很老了,但如果你玩 minScale,你可以得到你喜欢的东西。您可以阅读自述文件上的文档:

https://github.com/timmywil/jquery.panzoom/blob/master/README.md

试试这个,这对你有用

 (function() {
    var $section = $('section').first();
    $section.find('.panzoom').panzoom({
      increment: 0.3,
      minScale: 0.8,
      maxScale: 1.3
  });