最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - javascript finger slide detection - Stack Overflow

programmeradmin0浏览0评论

I'm trying to create a sliding checkbox like the one on the iphone.

I started with this script:

$('input[type=checkbox]').live('touchstart', function (e) {
            down_x = e.originalEvent.touches[0].pageX;
            $('input[type=checkbox]').live('touchmove', function (e) {up_x = e.originalEvent.touches[0].pageX;
            if ((down_x - up_x) > 1)  {$(this).change()}});
            });

But it does not seem to work. Any idea on how to implement this?

I'm trying to create a sliding checkbox like the one on the iphone.

I started with this script:

$('input[type=checkbox]').live('touchstart', function (e) {
            down_x = e.originalEvent.touches[0].pageX;
            $('input[type=checkbox]').live('touchmove', function (e) {up_x = e.originalEvent.touches[0].pageX;
            if ((down_x - up_x) > 1)  {$(this).change()}});
            });

But it does not seem to work. Any idea on how to implement this?

Share Improve this question edited May 15, 2017 at 12:35 cmplieger asked May 13, 2011 at 23:30 cmpliegercmplieger 7,35116 gold badges56 silver badges84 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 18

this was a fun little problem

I got it working just fine, it even works with a mouse :)

I tested it on my Ipad and Iphone and it is pretty cool.

would not take much work to flip this into a plugin but this should work just fine for you

the trick with working with ios mobile events is these three events

$('.toggle_box').bind('touchstart',touch_start);
$('.toggle_box').bind('touchmove',touch_move);
$('.toggle_box').bind('touchend',slide_end);   

http://jsfiddle.net/samccone/ZMkkd/

发布评论

评论列表(0)

  1. 暂无评论