Skip to content

Commit

Permalink
bump
Browse files Browse the repository at this point in the history
  • Loading branch information
kingdido999 committed Dec 2, 2016
1 parent 07586d7 commit 14b2c89
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 39 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zooming",
"version": "0.3.3",
"version": "0.3.4",
"homepage": "https://github.com/kingdido999/zooming",
"authors": [
"Desmond Ding <[email protected]>"
Expand Down
74 changes: 39 additions & 35 deletions dist/zooming.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* zooming - Image zoom with pure JavaScript.
* @version v0.3.3
* @version v0.3.4
* @link https://github.com/kingdido999/zooming
* @license MIT
*/
Expand Down Expand Up @@ -266,39 +266,43 @@
}

function calculateTransform (rect) {
var windowCenter = {
x: window.innerWidth / 2,
y: window.innerHeight / 2
}

var imgHalfWidth = rect.width / 2
var imgHalfHeight = rect.height / 2

var imgCenter = {
x: rect.left + imgHalfWidth,
y: rect.top + imgHalfHeight
}

// The vector to translate image to the window center
var translate = {
x: windowCenter.x - imgCenter.x,
y: windowCenter.y - imgCenter.y
}

// The distance between image edge and window edge
var distFromImageEdgeToWindowEdge = {
x: windowCenter.x - imgHalfWidth,
y: windowCenter.y - imgHalfHeight
}

// The additional scale is based on the smaller value of
// scaling horizontally and scaling vertically
var scaleHorizontally = distFromImageEdgeToWindowEdge.x / imgHalfWidth
var scaleVertically = distFromImageEdgeToWindowEdge.y / imgHalfHeight
var scale = options.scaleBase + Math.min(scaleHorizontally, scaleVertically)

// Translate the image to window center, then scale the image
return 'translate(' + translate.x + 'px,' + translate.y + 'px) ' + 'scale(' + scale + ',' + scale + ')'
var imgHalfWidth = rect.width / 2,
imgHalfHeight = rect.height / 2,

windowCenter = {
x: window.innerWidth / 2,
y: window.innerHeight / 2
},

imgCenter = {
x: rect.left + imgHalfWidth,
y: rect.top + imgHalfHeight
},

// The vector to translate image to the window center
translate = {
x: windowCenter.x - imgCenter.x,
y: windowCenter.y - imgCenter.y
},

// The distance between image edge and window edge
distFromImageEdgeToWindowEdge = {
x: windowCenter.x - imgHalfWidth,
y: windowCenter.y - imgHalfHeight
},

scaleHorizontally = distFromImageEdgeToWindowEdge.x / imgHalfWidth,
scaleVertically = distFromImageEdgeToWindowEdge.y / imgHalfHeight,

// The additional scale is based on the smaller value of
// scaling horizontally and scaling vertically
scale = options.scaleBase + Math.min(scaleHorizontally, scaleVertically),

transform =
'translate(' + translate.x + 'px,' + translate.y + 'px) ' +
'scale(' + scale + ',' + scale + ')'

return transform
}

function scrollHandler () {
Expand All @@ -316,7 +320,7 @@
}

function keydownHandler (e) {
if (event.keyCode === 27) api.close() // Esc
if (e.keyCode === 27) api.close() // Esc
}

// umd expose
Expand Down
4 changes: 2 additions & 2 deletions dist/zooming.min.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zooming",
"version": "0.3.3",
"version": "0.3.4",
"description": "Image zoom with pure JavaScript.",
"main": "src/zooming.js",
"repository": {
Expand Down

0 comments on commit 14b2c89

Please sign in to comment.