Skip to content

Commit

Permalink
Support to natural width/height
Browse files Browse the repository at this point in the history
Maximum zoom limits to natural image dimensions (width & height).
  • Loading branch information
indrimuska committed Nov 10, 2015
1 parent 39e6c16 commit a44d88d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Property | Type | Default | Description
---|---|---|---
duration | `integer` | `200` | Transition duration in milliseconds.
easing | `string` | `"linear"` | Transition property name.
scale | `float` | `0.9` | Maximum zoom scale (1 means full screen).
scale | `float` | `0.9` | If the image is bigger than the size of the page, it represent the maximum zoom scale according to page width/height (from 0 to 1).

Options can be passed via data attributes or JavaScript. For data attributes, append the option name to `data-`, as in `data-duration=""`.

Expand Down
3 changes: 1 addition & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zoomify",
"version": "0.2.3",
"version": "0.2.4",
"authors": [
"Indri Muska <[email protected]>"
],
Expand All @@ -25,7 +25,6 @@
"tests"
],
"dependencies": {
"angular": "~1.4.3",
"jquery": "~1.7.1"
}
}
8 changes: 5 additions & 3 deletions dist/zoomify.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@
var offset = this.$image.offset(),
width = this.$image.outerWidth(),
height = this.$image.outerHeight(),
nWidth = this.$image[0].naturalWidth || +Infinity,
nHeight = this.$image[0].naturalHeight || +Infinity,
wWidth = $(window).width(),
wHeight = $(window).height(),
scaleX = wWidth / width,
scaleY = wHeight / height,
scale = Math.min(scaleX, scaleY) * this.options.scale,
scaleX = Math.min(nWidth, wWidth * this.options.scale) / width,
scaleY = Math.min(nHeight, wHeight * this.options.scale) / height,
scale = Math.min(scaleX, scaleY),
translateX = (-offset.left + (wWidth - width) / 2) / scale,
translateY = (-offset.top + (wHeight - height) / 2 + $(document).scrollTop()) / scale;

Expand Down
4 changes: 2 additions & 2 deletions dist/zoomify.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zoomify",
"version": "0.2.3",
"version": "0.2.4",
"description": "Zoomify is a jQuery plugin for simple lightboxes with zoom effect.",
"main": "Gruntfile.js",
"repository": {
Expand All @@ -21,7 +21,7 @@
},
"homepage": "http://indrimuska.github.io/zoomify",
"dependencies": {
"angular": "~1.4.3"
"jquery": "~1.7.1"
},
"devDependencies": {
"grunt": "^0.4.5",
Expand Down
8 changes: 5 additions & 3 deletions src/zoomify.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@
var offset = this.$image.offset(),
width = this.$image.outerWidth(),
height = this.$image.outerHeight(),
nWidth = this.$image[0].naturalWidth || +Infinity,
nHeight = this.$image[0].naturalHeight || +Infinity,
wWidth = $(window).width(),
wHeight = $(window).height(),
scaleX = wWidth / width,
scaleY = wHeight / height,
scale = Math.min(scaleX, scaleY) * this.options.scale,
scaleX = Math.min(nWidth, wWidth * this.options.scale) / width,
scaleY = Math.min(nHeight, wHeight * this.options.scale) / height,
scale = Math.min(scaleX, scaleY),
translateX = (-offset.left + (wWidth - width) / 2) / scale,
translateY = (-offset.top + (wHeight - height) / 2 + $(document).scrollTop()) / scale;

Expand Down

0 comments on commit a44d88d

Please sign in to comment.