Skip to content

Instantly share code, notes, and snippets.

@cognitom
Last active May 7, 2020 08:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cognitom/de11ba8cf4f4b98ac8ab to your computer and use it in GitHub Desktop.
Save cognitom/de11ba8cf4f4b98ac8ab to your computer and use it in GitHub Desktop.
Partial Zoom in Mobile Safari
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
<style>
body {
margin: 40px 0 0 0;
padding: 0;
}
header,
footer {
position: absolute;
left: 0;
right: 0;
background: black;
color: white;
height: 20px;
padding: 10px;
}
header { top: 0 }
footer { bottom: 0 }
section {
position: absolute;
top: 40px;
bottom: 40px;
left: 0;
right: 0;
overflow: hidden;
}
</style>
<script>
var pinching = false;
var d0 = 1;
var d1 = 1;
document.addEventListener("touchmove", function(e){
if (e.touches.length == 2) {
if (!pinching) {
pinching = true;
d0 = Math.sqrt(
Math.pow(e.touches[1].screenX - e.touches[0].screenX, 2) +
Math.pow(e.touches[1].screenY - e.touches[0].screenY, 2)
);
} else {
d1 = Math.sqrt(
Math.pow(e.touches[1].screenX - e.touches[0].screenX, 2) +
Math.pow(e.touches[1].screenY - e.touches[0].screenY, 2)
);
document.querySelector("section").style.zoom = d1 / d0;
}
}
});
document.addEventListener("touchend", function(e){
pinching = false;
});
</script>
</head>
<body>
<header id="a">HEADER</header>
<section id="b">
<p>Hello world!</p>
<p>Hello world!</p>
<p>Hello world!</p>
<p>Hello world!</p>
<p>Hello world!</p>
<p>Hello world!</p>
<p>Hello world!</p>
<p>Hello world!</p>
<p>Hello world!</p>
<p>Hello world!</p>
</section>
<footer id="c">FOOTER</footer>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment