码迷,mamicode.com
首页 > 移动开发 > 详细

移动端长按效果实现

时间:2017-12-06 18:10:48      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:active   null   dcl   art   style   addclass   eve   function   package   

移动端长按效果实现

基本实现原理:监听touchstart事件,使用setTimeout延时,如果松开则清除该定时器

举个例子

    var pressTimer = null;
    $(‘.circle-tip‘).on(‘touchstart‘,function (e) {
        e.preventDefault();
        e.stopPropagation();
        pressTimer = setTimeout(function () {
                        $(‘.package-pop‘).addClass(‘active‘);
                    },600)
    }).on(‘touchend‘,function(e){
        e.preventDefault();
        e.stopPropagation();
        clearTimeout(pressTimer);
        $(‘.package-pop‘).removeClass(‘active‘);
    })

 

移动端长按效果实现

标签:active   null   dcl   art   style   addclass   eve   function   package   

原文地址:http://www.cnblogs.com/lw5116/p/7993290.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!