【发布时间】:2015-07-12 17:58:30
【问题描述】:
我在实习期间尝试为移动应用实现简单的滑动。在我将它实施到我的项目之前,我首先做了一个例子。当我向左滑动时,我将被重定向到下一页。但是,当我尝试向右滑动以返回上一页时,我需要大约 4 次尝试才能返回。
index.html
*{
padding: 0;
margin: 0;
}
div{
max-width: 1024px;
width: 100%;
height: 768px;
background: green;
}
<div></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4
/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5
/jquery.mobile.min.js"></script>
<script>
$("div").on("swipeleft",function(){
window.location = "nextpage.html";
});
});
</script>
下一页.html
*{
padding: 0;
margin: 0;
}
div{
max-width: 1024px;
width: 100%;
height: 768px;
background: blue;
}
<div></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4
/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5
/jquery.mobile.min.js"></script>
<script>
$("div").on("swiperight",function(){
window.location = "index.html";
});
});
</script>
【问题讨论】:
-
在你的 jquery 选择器中使用的
div可能会导致这种情况。尝试给最外层的 div 一个类,然后用它来委托swiperight事件 -
labs.rampinteractive.co.uk/touchSwipe/demos/Basic_swipe.html: 你可以看看这个JS..也许对你有用
-
@Renboy - 我认为您缺少脚本块的第一行 $(document).ready(function () {....
标签: jquery jquery-mobile