About Libraries API GitHub Status
jQuery special events for the gestures swipeleft, swiperight, swipeup and swipedown. 448 GitHub WTFPL licensed http://github.com/stephband/jquery.event.swipe Tags: touch, special, event, swipe Version 0.5.4 Asset Type All
Help support cdnjs You can contribute on GitHub to help make cdnjs sustainable! Or, donate $5 to cdnjs via Open Collective or Patreon. Demo page Usage
Use the following code to add swipe handler to a jQuery object. $("#touch-target").swipe(function(direction) { // your handler code }); OptionsOptions can be passed via an optional argument. $("#touch-target").swipe( function(direction) { // your handler code }, { preventDefault: true, mouse: true, pen: true, distance: 50 });
The handler argument A direction argument will be passed into the handler function when it's called. DescriptionFires when the user horizontally drag more than 30px over an element using id of the page to specify an event and on() method attaches the event handlers. ExampleFollowing example describes the use of swipe event in jQuery Mobile Framework. <!DOCTYPE html> <head> <title>Swipe Event</title> <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> <script> $(document).on("pagecreate","#page1",function() { $("p").on("swipe",function() { $("span").text("swipe event occurred!!!"); }); }); </script> </head> <body> <div data-role = "page" id = "page1"> <div data-role = "header"> <h2>Header</h2> </div> <div data-role = "main" class = "ui-content"> <p>It will display the text when you swipe here.</p> <span style = "color:orange"></span> </div> <div data-role = "footer"> <h2>Footer</h2> </div> </div> </body> </html> OutputLet's carry out the following steps to see how the above code works −
jquery_mobile_events.htm jQuery [jQuery] jQuery swipe event모바일 기기에서 좌우로 swipe에 대응하는 이벤트가 필요하게 됐다. jQuery Mobile 등의 라이브러리를 사용하면 되겠지만 단지 swipe 이벤트때문에 덩치가 큰 라이브러리를 사용하는 비효율적인 것 같아 다른 jQuery 플러그인을 찾아보니 아래와 같은 플러그인이 존재했다. jQuery.event.move jQuery.event.swipe 두 개의 플러그인을 이용하면 jQuery Mobile을 이용하지 않고 swipe 이벤트를 사용할 수 있게 된다. 한가지 사용 상의 주의점이 swipe 이벤트를 적용하게 되면 scroll 이벤트를 사용할 수 없게 된다. swipe 이벤트와 scroll 이벤트를 동시에 사용하기 위해서는 아래 코드를 추가해줘야 한다. jQuery('.mydiv') 위 코도를 swipe 이벤트를 사용하는 페이지에 추가해주면 scroll 이벤트도 사용할 수 있게 된다. 코드 중에 ‘.mydiv’ 이부분은 상황에 맞게 수정해서 사용해야 한다. |