我已经按照这个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>
发布于 2017-08-03 18:11:49
你有没有试着在#pageone上设置“快捷键”?
$(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>
发布于 2017-08-03 18:11:52
使用:
$("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>
发布于 2017-08-04 13:02:46
我找到了一个解决方案。
$(document).on('swipeleft', 'body', function(event){ });
$(document).on('swiperight', 'body', function(event){ });https://stackoverflow.com/questions/45481108
复制相似问题