Событие условной блокировки прокрутки / touchmove в мобильном сафари

iOS 5 теперь поддерживает встроенную поддержку переполнения: прокрутки.

Я бы хотел отключить событие touchmove для всего, кроме элементов с классом «scrollable» или их дочерних элементов.

Но я не могу заставить его работать; вот с чем я работал ниже:

<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>
7
задан ʞɔıu 22 December 2011 в 22:37
поделиться