iOS 5 hiện cho phép tràn dữ liệu gốc: hỗ trợ cuộn.Điều kiện chặn sự kiện di chuyển/touchmove trong safari di động
Điều tôi muốn làm là tắt sự kiện touchmove
cho mọi thứ trừ các thành phần có lớp 'có thể cuộn' hoặc con của họ.
Nhưng tôi dường như không làm cho nó hoạt động; đây là những gì tôi đã làm việc với bên dưới:
<html>
<head>
<style>
.scrollable {
height: 5em;
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
// doesn't seem to work
var handleMove = function (e) {
if (!$(e.target).parents().andSelf().hasClass('scrollable')) {
e.preventDefault();
}
};
document.addEventListener('touchmove', handleMove, true);
</script>
</head>
<body>
<div>
don't scroll if you drag here
</div>
<div class='scrollable'>
should be scrollable if you drag here
<ul>
<li>and here</li>
<li>and here</li>
<li>and here</li>
<li>and here</li>
<li>and here</li>
<li>and here</li>
<li>and here</li>
<li>and here</li>
</ul>
</div>
don't scroll if you drag here
</body>
</html>
Không có thẻ coffeescript nào ở bất kỳ nơi nào trong câu hỏi này cũng như không ai hỏi về coffeescript. –
Điều đó có làm cho câu trả lời kém hiệu quả hơn không? – Nevir
Vâng, tuyệt đối. –