This repository has been archived by the owner on Apr 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from cssho/zoon-in-out
implement zoon in/out (#43)
- Loading branch information
Showing
7 changed files
with
64 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const regexp = /scale\(([0-9\.]+)\)/g; | ||
window.addEventListener("load", function () { | ||
document.onwheel = function (event) { | ||
if (event.ctrlKey) { | ||
if (event.wheelDeltaY < 0) zoomOut(); | ||
else zoomIn(); | ||
} | ||
} | ||
}, false); | ||
|
||
function zoomIn() { | ||
var svgimg = document.getElementById('svgimg'); | ||
var zoomFloat = currentZoomValue(svgimg); | ||
zoomFloat += zoomFloat * 0.1; | ||
svgimg.style.transform = 'scale(' + zoomFloat + ')'; | ||
} | ||
|
||
function zoomOut() { | ||
var svgimg = document.getElementById('svgimg'); | ||
var zoomFloat = currentZoomValue(svgimg); | ||
zoomFloat -= zoomFloat * 0.1; | ||
if (zoomFloat < 0.1) return; | ||
svgimg.style.transform = 'scale(' + zoomFloat + ')'; | ||
}; | ||
|
||
function currentZoomValue(svgimg) { | ||
var zoom; | ||
if (svgimg.style.transform) { | ||
var array; | ||
while ((array = regexp.exec(svgimg.style.transform)) !== null) { | ||
zoom = array[1]; | ||
} | ||
} else | ||
zoom = '1.0'; | ||
var zoomFloat = parseFloat(zoom); | ||
return zoomFloat; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters