Bedingt block scrollen/touchmove-event in mobile safari

iOS 5 erlaubt nun das native overflow: scroll-Unterstützung.

Was ich möchte zu tun ist, deaktivieren Sie die touchmove Veranstaltung für alles, was mit Ausnahme von Elementen, die die 'Scrollbar' Klasse oder für Ihre Kinder.

Aber ich kann nicht scheinen, um es zu arbeiten; dies ist, was ich arbeite mit dem unten:

<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>
InformationsquelleAutor | 2011-12-22
Schreibe einen Kommentar