Skip to content

Instantly share code, notes, and snippets.

@GZShi
Created March 31, 2015 13:06
Show Gist options
  • Save GZShi/24fb740b4c7922d29a8c to your computer and use it in GitHub Desktop.
Save GZShi/24fb740b4c7922d29a8c to your computer and use it in GitHub Desktop.
iOS 8.2 safari fixed position bug
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="blue">
<title>bug</title>
<style>
.nav {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 60px;
z-index: 9;
background: #eee;
}
.body {
position: relative;
margin-top: 60px;
width: 100%;
height: 2000px;
z-index: 10;
background: #ddd;
}
.tricky {
-webkit-transform:translateZ(1px);
-moz-transform:translateZ(1px);
-o-transform:translateZ(1px);
transform:translateZ(1px);
}
p {
margin: 0;
padding: 0;
text-align: center;
font-size: 50px;
}
div#control {
margin-top: 100px;
text-align: center;
}
p#output {
font-size: 20px;
}
</style>
</head>
<body>
<div class="nav">
<p>zindex:9</p>
</div>
<div class="body">
<p>zindex:10</p>
<div id="control">
<button id="toggle"></button>
<p id="output"></p>
</div>
</div>
<script>
window.onload = function () {
var btn = document.querySelector('#toggle');
var body = document.querySelector('.body');
var output = document.querySelector('#output');
var isBug = false;
btn.addEventListener('click', function () {
isBug = !isBug;
if (isBug) {
btn.innerHTML = '处于问题状态';
body.classList.remove('tricky');
} else {
btn.innerHTML = '处于修复状态';
body.classList.add('tricky');
}
});
btn.click();
var tickHandle;
body.addEventListener('touchstart', function () {
clearTimeout(tickHandle);
output.innerHTML = 'touch start';
});
body.addEventListener('touchend', function () {
output.innerHTML = 'touch end';
tickHandle = setTimeout(function () {
output.innerHTML = '';
}, 1200);
});
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment