图片/图形

DOM元素移动缩放jQuery插件

阿里云


jQuery Panzoom 是一款非常实用的 HTML DOM 元素平移和缩放 jQuery 和 CSS3 插件。Panzoom 利用 CSS transforms 和 matrix 函数来为浏览器进行硬件(GPU)加速,它可以支持任何元素的平移和缩放:图片、视频、iframe、canvas 或文本等等。
IE8 及以下的浏览器不支持这个插件。

Mobile support

Panzoom 支持移动手机的触摸姿势,也支持使用手指来缩放元素大小。它完全可以同时在桌面设备和移动手机上同时使用。它可以支持 iOS 和 Android 设备,同时支持 Pointer(IE11+)、touch 和 mouse 事件。

也想出现在这里?联系我们
创客主机

SVG support

Panzoom 可以在支持 SVG 的浏览器中直接对 SVG 元素进行平移和缩放。注意 SVG 元素上不会有动画效果,但是可以通过外部插件来手动覆盖 setTransform()方法,并整合一个补间动画库(如 tween.js)来实现。

使用方法

使用该元素平移和缩放插件需要引入 jQuery 和 jquery.panzoom.js 文件。

  1. <script src="js/jquery.min.js"></script>
  2. <script src="js/jquery.panzoom.js"></script>

也可以通过 AMD 来装载模块:

  1. define([ "jquery", "plugins/jquery.panzoom" ], function( $ ) {
  2.   $(document).ready(function() {
  3.     $(".panzoom-elements").panzoom();
  4.   });
  5. });

插件初始化

  1. $(".panzoom-elements").panzoom();
  2.  
  3. // Pass options
  4. $("a.panzoom-elements").panzoom({
  5.   minScale: 0,
  6.   $zoomRange: $("input[type='range']")
  7. });

配置参数

所有的参数都可以通过 option 方法来传入对象参数进行覆盖。

  1. Panzoom.defaults = {
  2.   // Should always be non-empty
  3.   // Used to bind jQuery events without collisions
  4.   // A guid is not added here as different instantiations/versions of Panzoom
  5.   // on the same element is not supported.
  6.   eventNamespace: ".panzoom",
  7.  
  8.   // Whether or not to transition the scale
  9.   transition: true,
  10.  
  11.   // Default cursor style for the element
  12.   cursor: "move",
  13.  
  14.   // There may be some use cases for zooming without panning or vice versa
  15.   // NOTE: disablePan also disables focal point zooming
  16.   disablePan: false,
  17.   disableZoom: false,
  18.  
  19.   // The increment at which to zoom
  20.   // adds/subtracts to the scale each time zoomIn/Out is called
  21.   increment: 0.3,
  22.  
  23.   minScale: 0.4,
  24.   maxScale: 5,
  25.  
  26.   // The default step for the range input
  27.   // Precendence: default < HTML attribute < option setting
  28.   rangeStep: 0.05,
  29.  
  30.   // Animation duration (ms)
  31.   duration: 200,
  32.   // CSS easing used for scale transition
  33.   easing: "ease-in-out",
  34.  
  35.   // Indicate that the element should be contained within it's parent when panning
  36.   // Note: this does not affect zooming outside of the parent
  37.   // Set this value to 'invert' to only allow panning outside of the parent element (the opposite of the normal use of contain)
  38.   // 'invert' is useful for a large Panzoom element where you don't want to show anything behind it
  39.   contain: false,
  40.  
  41.   // Transform value to which to always reset (string)
  42.   // Defaults to the original transform on the element when Panzoom is initialized
  43.   startTransform: undefined,
  44.  
  45.   // This optional jQuery collection can be set to specify all of the elements
  46.   // on which the transform should always be set.
  47.   // It should have at least one element.
  48.   // This is mainly used for delegating the pan and zoom transform settings
  49.   // to another element or multiple elements.
  50.   // The default is the Panzoom element wrapped in jQuery
  51.   // See the [demo](http://timmywil.github.io/jquery.panzoom/demo/#set) for an example.
  52.   // Note: only one Panzoom element will still handle events for a Panzoom instance.
  53.   // Use multiple Panzoom instances for that use case.
  54.   $set: $elem,
  55.  
  56.   // Zoom buttons/links collection (you can also bind these yourself - e.g. `$button.on("click", function( e ) { e.preventDefault(); $elem.panzoom("zoomIn"); });` )
  57.   $zoomIn: $(),
  58.   $zoomOut: $(),
  59.   // Range input on which to bind zooming functionality
  60.   $zoomRange: $(),
  61.   // Reset buttons/links collection on which to bind the reset method
  62.   $reset: $(),
  63.   // For convenience, these options will be bound to Panzoom events
  64.   // These can all be bound normally on the Panzoom element
  65.   // e.g. `$elem.on("panzoomend", function( e, panzoom ) { console.log( panzoom.getMatrix() ); });`
  66.   onStart: undefined,
  67.   onChange: undefined,
  68.   onZoom: undefined,
  69.   onPan: undefined,
  70.   onEnd: undefined,
  71.   onReset: undefined
  72. };

更多参考:https://github.com/timmywil/jquery.panzoom

DOM 元素移动缩放 jQuery 插件

已有 532 人购买
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!