Created
December 4, 2015 09:06
-
-
Save nexpr/200e2973eb7b4f6f8838 to your computer and use it in GitHub Desktop.
右クリック+ホイールでズームレベル変更(たしかChromeのみ動く)
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
!function(){ | |
var zoom_active = false | |
var zoom_change = false | |
var zoom_per = 1.08 | |
var init = function(){ | |
document.body.style.zoom = 1 | |
} | |
if(document.readyState === "complete"){ | |
init() | |
}else{ | |
window.addEventListener("load", init, false) | |
} | |
window.addEventListener("mousedown", function(eve){ | |
eve.button === 2 && (zoom_active = true, zoom_change = false) | |
eve.button === 1 && zoom_active && init() | |
}, true) | |
window.addEventListener("mouseup", function(eve){ | |
eve.button === 2 && (zoom_active = false) | |
}, true) | |
window.addEventListener("mousewheel", function(eve){ | |
if(zoom_active){ | |
if(eve.deltaY < 0){ // zoom in | |
window.top.document.body.style.zoom *= zoom_per | |
}else if(eve.deltaY > 0){ // zoom out | |
window.top.document.body.style.zoom /= zoom_per | |
} | |
zoom_change = true | |
eve.preventDefault() | |
} | |
}, true) | |
// cancel right click action when zoom was changed | |
window.addEventListener("contextmenu", function(eve){ | |
zoom_change && eve.preventDefault() | |
}, false) | |
}() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment