jQuery Panzoom 是一款非常实用的 HTML DOM 元素平移和缩放 jQuery 和 CSS3 插件。Panzoom 利用 CSS transforms 和 matrix 函数来为浏览器进行硬件(GPU)加速,它可以支持任何元素的平移和缩放:图片、视频、iframe、canvas 或文本等等。
IE8 及以下的浏览器不支持这个插件。
Panzoom 支持移动手机的触摸姿势,也支持使用手指来缩放元素大小。它完全可以同时在桌面设备和移动手机上同时使用。它可以支持 iOS 和 Android 设备,同时支持 Pointer(IE11+)、touch 和 mouse 事件。
Panzoom 可以在支持 SVG 的浏览器中直接对 SVG 元素进行平移和缩放。注意 SVG 元素上不会有动画效果,但是可以通过外部插件来手动覆盖 setTransform()方法,并整合一个补间动画库(如 tween.js)来实现。
使用该元素平移和缩放插件需要引入 jQuery 和 jquery.panzoom.js 文件。
<script src="js/jquery.min.js"></script>
<script src="js/jquery.panzoom.js"></script>
也可以通过 AMD 来装载模块:
define([ "jquery", "plugins/jquery.panzoom" ], function( $ ) {
$(document).ready(function() {
$(".panzoom-elements").panzoom();
});
});
插件初始化
$(".panzoom-elements").panzoom();
// Pass options
$("a.panzoom-elements").panzoom({
minScale: 0,
$zoomRange: $("input[type='range']")
});
所有的参数都可以通过 option 方法来传入对象参数进行覆盖。
Panzoom.defaults = {
// Should always be non-empty
// Used to bind jQuery events without collisions
// A guid is not added here as different instantiations/versions of Panzoom
// on the same element is not supported.
eventNamespace: ".panzoom",
// Whether or not to transition the scale
transition: true,
// Default cursor style for the element
cursor: "move",
// There may be some use cases for zooming without panning or vice versa
// NOTE: disablePan also disables focal point zooming
disablePan: false,
disableZoom: false,
// The increment at which to zoom
// adds/subtracts to the scale each time zoomIn/Out is called
increment: 0.3,
minScale: 0.4,
maxScale: 5,
// The default step for the range input
// Precendence: default < HTML attribute < option setting
rangeStep: 0.05,
// Animation duration (ms)
duration: 200,
// CSS easing used for scale transition
easing: "ease-in-out",
// Indicate that the element should be contained within it's parent when panning
// Note: this does not affect zooming outside of the parent
// Set this value to 'invert' to only allow panning outside of the parent element (the opposite of the normal use of contain)
// 'invert' is useful for a large Panzoom element where you don't want to show anything behind it
contain: false,
// Transform value to which to always reset (string)
// Defaults to the original transform on the element when Panzoom is initialized
startTransform: undefined,
// This optional jQuery collection can be set to specify all of the elements
// on which the transform should always be set.
// It should have at least one element.
// This is mainly used for delegating the pan and zoom transform settings
// to another element or multiple elements.
// The default is the Panzoom element wrapped in jQuery
// See the [demo](http://timmywil.github.io/jquery.panzoom/demo/#set) for an example.
// Note: only one Panzoom element will still handle events for a Panzoom instance.
// Use multiple Panzoom instances for that use case.
$set: $elem,
// Zoom buttons/links collection (you can also bind these yourself - e.g. `$button.on("click", function( e ) { e.preventDefault(); $elem.panzoom("zoomIn"); });` )
$zoomIn: $(),
$zoomOut: $(),
// Range input on which to bind zooming functionality
$zoomRange: $(),
// Reset buttons/links collection on which to bind the reset method
$reset: $(),
// For convenience, these options will be bound to Panzoom events
// These can all be bound normally on the Panzoom element
// e.g. `$elem.on("panzoomend", function( e, panzoom ) { console.log( panzoom.getMatrix() ); });`
onStart: undefined,
onChange: undefined,
onZoom: undefined,
onPan: undefined,
onEnd: undefined,
onReset: undefined
};
更多参考:https://github.com/timmywil/jquery.panzoom
演示地址 | 下载地址 |
专业提供WordPress主题安装、深度汉化、加速优化等各类网站建设服务,详询在线客服!