【发布时间】:2015-03-20 20:02:00
【问题描述】:
这是IOS 5 (safari) bug with HTML touch events on "position:fixed" div的类似问题
有人说这个bug已经修复了。但是,在 iOS 8 上,我发现它只有在您慢慢点击并滚动页面时才会修复。
这是我的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>Document</title>
<style>
header {
position: fixed;
width: 100%;
height: 600px;
top: 0;
color: #fff;
background: rgba(0, 0, 0, 0.9);
z-index:100;
}
.content {
height: 10000px;
background: url(http://placehold.it/350x150&text=Background);
}
</style>
</head>
<body>
<header></header>
<section class="content"></section>
<script type="text/javascript" src="jquery.js"></script>
<script>
(function($) {
'use strict';
$('header').on('touchend', function(event) {
event.stopPropagation();
$('<p>Tap on float content.</p>').appendTo('header');
// hack 1
var $temp = $('<div style="height: 20000px"></div>');
$temp.appendTo('body');
setTimeout(function(){
$temp.remove();
}, 1);
});
$(document).on('touchend', function() {
$('<p>Tap on UNDER content.</p>').appendTo('header');
});
// hack 2
$('body').bind('touchstart', function(e) {});
}(jQuery));
</script>
</body>
</html>
您可以通过以下两种不同的方式找到错误:
- 在
<head>区域快速滑动和滚动页面数次。 - 在 .content 区域上滑动,然后在页面停止滚动前快速点击
<header>区域。
在这两种情况下,有时您会发现“点击 UNDER 内容”。当您点击<header> 区域时输出。
更新:
第三种情况:
- 在 .content 区域上滑动,然后在页面停止滚动之前再次快速点击 .content 区域,然后点击
<header>区域。在这种情况下,点击<header>区域不会输出任何内容。
我已经尝试了一些技巧,例如“为<body> 添加触摸启动事件”、“添加临时<div>”。它们都不起作用。
关于如何解决这个问题的任何想法?谢谢。
【问题讨论】:
标签: javascript jquery ios css