【问题标题】:how to make Jquery swipe function work on whole page如何使 Jquery 滑动功能在整个页面上工作
【发布时间】:2023-04-02 15:15:02
【问题描述】:

我已经按照这个link 创建了一个向右滑动的功能。但是,这仅在您在文本内向右滑动时才有效。当我在此页面的任何位置向右滑动时,如何使向右滑动功能触发。谢谢!

    $(document).on("pagecreate","#pageone",function(){
      $("p").on("swiperight",function(){
        $(this).hide();
      });                       
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
    <html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
    <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
    </head>
    <body>
    <div data-role="page" id="pageone">
      <div data-role="header">
        <h1>The swiperight Event</h1>
      </div>
    
      <div data-role="main" class="ui-content">
        <p>If you swipe me in the right direction, I will disappear.</p>
        <p>Swipe me in the right direction!</p>
        <p>Swipe me in the right direction, too!</p>
      </div>
    
      <div data-role="footer">
        <h1>Footer Text</h1>
      </div>
    </div> 
    
    </body>
    </html>

【问题讨论】:

    标签: javascript jquery html swipe


    【解决方案1】:

    您是否尝试在#pageone 上设置“swiperight”?

        $(document).on("pagecreate","#pageone",function(){
          $("#pageone").on("swiperight",function(){
            $(this).hide();
          });                       
        });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <!DOCTYPE html>
        <html>
        <head>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
        <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
        <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
        </head>
        <body>
        <div data-role="page" id="pageone">
          <div data-role="header">
            <h1>The swiperight Event</h1>
          </div>
        
          <div data-role="main" class="ui-content">
            <p>If you swipe me in the right direction, I will disappear.</p>
            <p>Swipe me in the right direction!</p>
            <p>Swipe me in the right direction, too!</p>
          </div>
        
          <div data-role="footer">
            <h1>Footer Text</h1>
          </div>
        </div> 
        
        </body>
        </html>

    【讨论】:

      【解决方案2】:

      使用:

      $("body").on("swiperight",function(){
        console.log('swipe happend, what to do now');
      });
      

      $("body").on("swiperight",function(){
        console.log('swipe happend, what to do now');
      });
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <!DOCTYPE html>
          <html>
          <head>
          <meta name="viewport" content="width=device-width, initial-scale=1">
          <link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
          <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
          <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
          </head>
          <body>
          <div data-role="page" id="pageone">
            <div data-role="header">
              <h1>The swiperight Event</h1>
            </div>
          
            <div data-role="main" class="ui-content">
              <p>If you swipe me in the right direction, I will disappear.</p>
              <p>Swipe me in the right direction!</p>
              <p>Swipe me in the right direction, too!</p>
            </div>
          
            <div data-role="footer">
              <h1>Footer Text</h1>
            </div>
          </div> 
          
          </body>
          </html>

      【讨论】:

        【解决方案3】:

        我找到了解决办法。

        $(document).on('swipeleft', 'body', function(event){ });
        $(document).on('swiperight', 'body', function(event){ });
        

        【讨论】:

          【解决方案4】:

          我无法让上述任何一项工作。但是,这确实

          jQuery(function(){
          
            jQuery( "body" ).on( "swipeleft", swipeleftHandler );
            jQuery( "body" ).on( "swiperight", swiperightHandler );
          
            function swipeleftHandler( event ){
              // do stuff here
            }
            function swiperightHandler( event ){
              // do stuff here
            }
          });
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2012-04-27
            • 1970-01-01
            • 1970-01-01
            • 2012-04-28
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多