Skip to content

Instantly share code, notes, and snippets.

@nexpr
Created December 4, 2015 09:06
Show Gist options
  • Save nexpr/200e2973eb7b4f6f8838 to your computer and use it in GitHub Desktop.
Save nexpr/200e2973eb7b4f6f8838 to your computer and use it in GitHub Desktop.
右クリック+ホイールでズームレベル変更(たしかChromeのみ動く)
!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