実際に使用している lib はわかりませんが、jQuery を想定します (jQ 以外のものを使用している場合は、browser-native-js にも同じコードを投稿します)。
$bod.delegate('*', 'touchstart',function(e)
{
if ($(this) !== $altNav)
{
e.preventDefault();
//and /or
return false;
}
//current event target is $altNav, handle accordingly
});
それはすべての世話をする必要があります。ここでのコールバックは、すべてのtouchmove イベントを処理し、 以外のpreventDefault
要素でイベントがトリガーされるたびにメソッドを呼び出します。$altNav
std browser-js では、このコードは次のようになります。
document.body.addEventListener('touchmove',function(e)
{
e = e || window.event;
var target = e.target || e.srcElement;
//in case $altNav is a class:
if (!target.className.match(/\baltNav\b/))
{
e.returnValue = false;
e.cancelBubble = true;
if (e.preventDefault)
{
e.preventDefault();
e.stopPropagation();
}
return false;//or return e, doesn't matter
}
//target is a reference to an $altNav element here, e is the event object, go mad
},false);
が特定の ID を持つ要素である場合$altNav
は、その要素を次のように置き換えます。
幸運を祈ります。これが役立つことを願っていますtarget.className.match()
。target.id === 'altNav'