Last active
September 11, 2021 06:08
-
-
Save davorpa/62b1a394738da893c8069cf8f411d145 to your computer and use it in GitHub Desktop.
A easy script to put at your HTML body end to fix scale gestures on iOS devices
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(document, undefined) { // IIFE::start | |
if (!navigator.userAgent.match(/iPhone/i)) return; // only for iPhone | |
var metas = document.getElementsByTagName("meta"), | |
NORMAL_SCALE = 1.0, | |
MIN_SCALE = 0.25, | |
MAX_SCALE = 1.6; | |
initialize(); | |
// document.addEventListener("gesturestart", onGestureStart, false); | |
document.addEventListener("touchstart", onGestureStart, false); | |
document.addEventListener("touchend", onGestureEnd, false); | |
function changeViewportContent(content) { | |
for (var i = 0; i < metas.length; i++) { | |
if (metas[i].name == "viewport") { | |
metas[i].content = content; | |
} | |
} | |
} | |
function setViewportScale(min, max) { | |
for (var i = 0; i < metas.length; i++) { | |
if (metas[i].name == "viewport") { | |
metas[i].content = "width=device-width, minimum-scale=" + (min) + ", maximum-scale=" + (max); | |
} | |
} | |
} | |
function initialize() { | |
changeViewportContent("width=device-width, minimum-scale=1.0, maximum-scale=1.0"); | |
} | |
function onGestureStart(event) { | |
changeViewportContent("width=device-width, minimum-scale=0.25, maximum-scale=1.6"); | |
} | |
function onGestureEnd(event) { | |
initialize(); | |
}; | |
})(document); // IIFE::end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment