JQ监听单击、长按、拖动事件

前端开发   发布日期:2023年05月04日   浏览次数:536
  1. //JQ移动端页面监听单击、长按、拖动事件,直接看代码:
  2.  
  3. <div class="box">按钮</div>
  4. <script>
  5. $(function() {
  6. //console.log($('.box'));
  7. $(".box").on({
  8. touchstart: function(e) {
  9. //长按触发事件
  10. timeOutEvent = setTimeout(function() {
  11. timeOutEvent = 0;
  12. alert("你长按了");
  13. }, 1000)
  14. },
  15. touchmove: function() {
  16. clearTimeout(timeOutEvent);
  17. timeOutEvent = 0;
  18. alert('移动了')
  19. },
  20. touchend: function() {
  21. clearTimeout(timeOutEvent);
  22. if (timeOutEvent != 0) {
  23. alert("你点击了");
  24. }
  25. return false;
  26. }
  27. });
  28. });
  29. </script>


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