现在,我拥有一个网页函数,该函数在窗口中无处不在,不包括限量性。我已经使限制性物品重叠了主要内容。我该如何确定此区域不会触发该功能?我尝试了e.preventDefault();
,但似乎不起作用。谢谢
$(document).swipe(function(){
...............
};
$('#flip').swiperight(function(e){
e.stopPropagation();
e.preventDefault();
});
更新:所有狂欢代码:
CSS:
*
{
-webkit-user-select: none; /* disable auto selection (select/selectall when long tap)*/
-webkit-touch-callout: none; /* disable magnifier*/
}
#flip
{
position:absolute;
background-color:red;
z-index:10;
height: 100%;
width:60%;
left:20%;
}
JS:
$(document).swipeleft(function(){
//check the case when popup and thumbnail slide bar is not exist
if ($("#popup").length == '0' && parseInt($('#all_pages').css('left')) != '0'){
if (checkOrientation (orientation)== 'landscape'){
var pageLand = $('#book').turn('view');
pageLand = pageLand[1];
if (pageLand + 1 < countImage && pageLand != '0')
$('#book').turn('page', pageLand + 1);
}
else{
var pagePort = $('#book').turn('page');
if (pagePort + 1 < countImage && pagePort != '0')
$('#book').turn('page', pagePort + 1);
}
}
});
$(document).swiperight(function(){
//check the case when popup and thumbnail slide bar is not exist
if ($("#popup").length == '0' && parseInt($('#all_pages').css('left')) != '0'){
if (checkOrientation (orientation)== 'landscape'){
var pageLand = $('#book').turn('view');
pageLand = pageLand[0];
if (pageLand - 1 > 0)
$('#book').turn('page', pageLand - 1);
}
else{
var pagePort = $('#book').turn('page');
if (pagePort - 1 > 0)
$('#book').turn('page', pagePort - 1);
}
}
});
$('#flip').swiperight(function(e){
alert ('test');
e.stopPropagation();
e.preventDefault();
});
$('#flip').swipeleft(function(e){
alert ('test');
e.stopPropagation();
e.preventDefault();
});
尝试以下代码。您需要停止活动从子节点到父文档的气泡。
$('#restrictArea').swipe(function(e){
e.stopPropagation();
e.preventDefault();
});
而不是 $(document)
您无法在某些DIV
上绑定。Swipe(可能是高度/宽度100%)?然后,您只需使用z-index
就可以比DIV
更高的#restrictArea
,就可以了。
另外,在您的代码中,您尝试进行预防违规,但是变量e未在您的函数中定义/传递。
在您的代码中,您没有正确关闭功能:
$(document).swipe(function(){
...............
});
//^-----------you missed out this
$('#restrictArea').swipe(function(e){
//---------------^-----------you missed out this
e.preventDefault();
});
//-^---------------------------------this too
jQuery没有.swipe
处理程序,但jQuery手机具有这样的代码:
$(document).bind("pageinit", function(event, data) {
$('#restrictArea').swipe(function(e) {
e.preventDefault();
});
});