JQ移动端页面监听单击、长按、拖动事件

前端开发   发布日期:2023年05月31日   浏览次数:576

JQ移动端页面监听单击、长按、拖动事件,直接看代码:

  1. <div class="box">按钮</div>
  2. <script>
  3. $(function() {
  4. //console.log($('.box'));
  5. $(".box").on({
  6. touchstart: function(e) {
  7. //长按触发事件
  8. timeOutEvent = setTimeout(function() {
  9. timeOutEvent = 0;
  10. alert("你长按了");
  11. }, 1000)
  12. },
  13. touchmove: function() {
  14. clearTimeout(timeOutEvent);
  15. timeOutEvent = 0;
  16. alert('移动了')
  17. },
  18. touchend: function() {
  19. clearTimeout(timeOutEvent);
  20. if (timeOutEvent != 0) {
  21. alert("你点击了");
  22. }
  23. return false;
  24. }
  25. });
  26. });
  27. </script>

以上就是JQ移动端页面监听单击、长按、拖动事件的详细内容,更多关于JQ移动端页面监听单击、长按、拖动事件的资料请关注九品源码其它相关文章!