Skip to content

Commit

Permalink
[zoom] remove exponential option; add linear option
Browse files Browse the repository at this point in the history
Fixes gh-257
  • Loading branch information
timmywil committed Aug 29, 2016
1 parent 3ab5046 commit f86ac04
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 35 deletions.
11 changes: 7 additions & 4 deletions README.md
Expand Up @@ -100,12 +100,15 @@ Panzoom.defaults = {
which: 1,

// The increment at which to zoom
// adds/subtracts to the scale each time zoomIn/Out is called
// Should be a number greater than 0
increment: 0.3,

// Turns on exponential zooming
// If false, zooming will be incremented linearly
exponential: true,
// When no scale is passed, this option tells
// the `zoom` method to increment
// the scale *linearly* based on the increment option.
// This often ends up looking like very little happened at larger zoom levels.
// The default is to multiply/divide the scale based on the increment.
linearZoom: false,

// Pan only when the scale is greater than minScale
panOnlyWhenZoomed: false,
Expand Down
1 change: 0 additions & 1 deletion demo/index.html
Expand Up @@ -563,7 +563,6 @@ <h1>Use the mousewheel to zoom on a focal point</h1>
var delta = e.delta || e.originalEvent.wheelDelta;
var zoomOut = delta ? delta < 0 : e.originalEvent.deltaY > 0;
$panzoom.panzoom('zoom', zoomOut, {
increment: 0.1,
animate: false,
focal: e
});
Expand Down
27 changes: 12 additions & 15 deletions dist/jquery.panzoom.js
@@ -1,6 +1,6 @@
/**
* @license jquery.panzoom.js v3.2.2
* Updated: Sat Aug 27 2016
* Updated: Sun Aug 28 2016
* Add pan and zoom functionality to any element
* Copyright (c) timmy willison
* Released under the MIT license
Expand Down Expand Up @@ -297,12 +297,15 @@
which: 1,

// The increment at which to zoom
// adds/subtracts to the scale each time zoomIn/Out is called
// Should be a number greater than 0
increment: 0.3,

// Turns on exponential zooming
// If false, zooming will be incremented linearly
exponential: true,
// When no scale is passed, this option tells
// the `zoom` method to increment
// the scale *linearly* based on the increment option.
// This often ends up looking like very little happened at larger zoom levels.
// The default is to multiply/divide the scale based on the increment.
linearZoom: false,

// Pan only when the scale is greater than minScale
panOnlyWhenZoomed: false,
Expand Down Expand Up @@ -694,22 +697,16 @@

// Calculate zoom based on increment
if (typeof scale !== 'number') {
// Just use a number a little greater than 1
// Below 1 can use normal increments
if (options.exponential && startScale - options.increment >= 1) {
scale = Math[scale ? 'sqrt' : 'pow'](startScale, 2);
} else {
if (options.linearZoom) {
scale = startScale + (options.increment * (scale ? -1 : 1));
} else {
scale = scale ? (startScale / (1 + options.increment)) : (startScale * (1 + options.increment));
}
animate = true;
}

// Constrain scale
if (scale > options.maxScale) {
scale = options.maxScale;
} else if (scale < options.minScale) {
scale = options.minScale;
}
scale = Math.max(Math.min(scale, options.maxScale), options.minScale);

// Calculate focal point based on scale
var focal = options.focal;
Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.panzoom.min.js

Large diffs are not rendered by default.

25 changes: 11 additions & 14 deletions src/panzoom.js
Expand Up @@ -297,12 +297,15 @@
which: 1,

// The increment at which to zoom
// adds/subtracts to the scale each time zoomIn/Out is called
// Should be a number greater than 0
increment: 0.3,

// Turns on exponential zooming
// If false, zooming will be incremented linearly
exponential: true,
// When no scale is passed, this option tells
// the `zoom` method to increment
// the scale *linearly* based on the increment option.
// This often ends up looking like very little happened at larger zoom levels.
// The default is to multiply/divide the scale based on the increment.
linearZoom: false,

// Pan only when the scale is greater than minScale
panOnlyWhenZoomed: false,
Expand Down Expand Up @@ -694,22 +697,16 @@

// Calculate zoom based on increment
if (typeof scale !== 'number') {
// Just use a number a little greater than 1
// Below 1 can use normal increments
if (options.exponential && startScale - options.increment >= 1) {
scale = Math[scale ? 'sqrt' : 'pow'](startScale, 2);
} else {
if (options.linearZoom) {
scale = startScale + (options.increment * (scale ? -1 : 1));
} else {
scale = scale ? (startScale / (1 + options.increment)) : (startScale * (1 + options.increment));
}
animate = true;
}

// Constrain scale
if (scale > options.maxScale) {
scale = options.maxScale;
} else if (scale < options.minScale) {
scale = options.minScale;
}
scale = Math.max(Math.min(scale, options.maxScale), options.minScale);

// Calculate focal point based on scale
var focal = options.focal;
Expand Down

0 comments on commit f86ac04

Please sign in to comment.