首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何让Jquery滑动功能在整个页面上工作

问如何让Jquery滑动功能在整个页面上工作
EN

Stack Overflow用户
提问于 2017-08-03 18:08:01
回答 4查看 2.6K关注 0票数 0

我已经按照这个link创建了一个向右滑动的功能。然而,只有当你在文本内部滑动时,这才能起作用。如何当我在此页面的任何位置向右滑动时触发向右滑动功能。谢谢!

​

代码语言:javascript
复制
    $(document).on("pagecreate","#pageone",function(){
      $("p").on("swiperight",function(){
        $(this).hide();
      });                       
    });
代码语言:javascript
复制
<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>

​

EN

回答 4

Stack Overflow用户

发布于 2017-08-03 18:11:49

你有没有试着在#pageone上设置“快捷键”?

​

代码语言:javascript
复制
    $(document).on("pagecreate","#pageone",function(){
      $("#pageone").on("swiperight",function(){
        $(this).hide();
      });                       
    });
代码语言:javascript
复制
<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>

​

票数 0
EN

Stack Overflow用户

发布于 2017-08-03 18:11:52

使用:

代码语言:javascript
复制
$("body").on("swiperight",function(){
  console.log('swipe happend, what to do now');
});

​

代码语言:javascript
复制
$("body").on("swiperight",function(){
  console.log('swipe happend, what to do now');
});
代码语言:javascript
复制
<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>

​

票数 0
EN

Stack Overflow用户

发布于 2017-08-04 13:02:46

我找到了一个解决方案。

代码语言:javascript
复制
$(document).on('swipeleft', 'body', function(event){ });
$(document).on('swiperight', 'body', function(event){ });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45481108

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档