3

これで、restrictAreaを除くすべてのウィンドウでトリガーされるWebページ関数ができました。私はrestrictAreaをメインコンテンツとオーバーラップさせました。この領域が機能をトリガーしないように指定するにはどうすればよいですか?試し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();
    });
4

3 に答える 3

2

次のコードを試してください。子ノードから親ドキュメントへのイベントのバブリングを停止する必要があります。

$('#restrictArea').swipe(function(e){
  e.stopPropagation();
  e.preventDefault();
});
于 2012-12-20T07:14:00.687 に答える
0

一部(高さ/幅100%の可能性があります)で.swipeをバインドすることは$(document)できませんか?DIV次に、より高い値で作成するだけで#restrictArea、問題ないはずです。z-indexDIV

また、コードでpreventDefaultを実行しようとしましたが、変数eが関数で定義/渡されていません。

于 2012-12-20T07:13:33.213 に答える
0

コードでは、関数が適切に閉じられていません。

  $(document).swipe(function(){
   ...............
  });
 //^-----------you missed out this

  $('#restrictArea').swipe(function(e){
                   //---------------^-----------you missed out this
      e.preventDefault();
  });
//-^---------------------------------this too

jQueryにはハンドラーがありませんが、.swipejQuery mobileにはハンドラーがあるため、コードは次のようになります。

$(document).bind("pageinit", function(event, data) {
    $('#restrictArea').swipe(function(e) {
        e.preventDefault();
    });
});
于 2012-12-20T07:24:27.643 に答える