首页 > 微信端setinterval与微信的按住屏幕滑动事件冲突

微信端setinterval与微信的按住屏幕滑动事件冲突

微信端setinterval与微信的按住屏幕滑动事件(按住屏幕不放进行上下或者左右滑动)冲突,在setinterval进行倒计时的执行,但是微信端的滑动事件让setinterval不执行,只有手指放开才继续执行,查文档,使用preventDefault函数在touchmove可以让setinterval不受影响,但是失去了微信端本来流程的滑动效果,使用js模拟滑动,效果很一般。求大神有没有更好的解决方案


用requestAnimationFrame 试试,没试过随便说一下哈。


var timer = (function() {

    return function(json) {
        
        if (json.currentTime) {

            var now = new Date();

            var year = now.getFullYear();//返回年份(4位数字)

            var month = now.getMonth() + 1;//返回月份(0-11,所以+1)

            var day = now.getDate();//返回某天(1-31)

            var h = now.getHours();//返回小时(0-23)

            var m = now.getMinutes();//返回分钟(0-59)

            var s = now.getSeconds();//返回秒数(0-59)
            //补O
            m = m < 10 ? '0' + m : m;

            s = s < 10 ? '0' + s : s;

            var weekday = [ '星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六' ];

            $(json.objId).html(year + '年'
    • month + '月' + day + '日' + weekday[now.getDay()]

    • ' ' + h + ':' + m + ':' + s);

                setTimeout(function() {
                    timer(json)
                }, 1000);
      
            } else {
      
    1. endtime = new Date(json.endtime);//结束时间

    2. nowtime = new Date();//当前时间

    3. lefttime = parseInt((endtime.getTime() - nowtime.getTime()) / 1000); //计算差的秒数

                //一天24小时  一小时60分钟  一分钟60秒
      
    4. = parseInt(lefttime / 3600 / 24);

    5. = parseInt((lefttime / 3600) % 24);

    6. = parseInt((lefttime / 60) % 60);

    7. = parseInt(lefttime % 60);

                $(json.objId).html(d + "天" + h    + "小时" + m + "分" + s + "秒");            
    8. (lefttime > 0) {

                    setTimeout(function() {
                        timer(json)
                    }, 1000);
                }else{
                    $(json.objId).html("对不起,活动已结束");
                }
            }
      
        }
      

    })()
    window.onload = function() {

       /*     显示当前时间
       timer({
           currentTime : true,
           objId : '#thisTime'
       }) */
       timer({
           objId : '#restTime', //div id 显示
    1. : ‘2016/07/12 18:00’ //必须是这个格式或者是date类型

         })

      }


    hammer.js
    https://hammerjs.github.io/;
    预填一坑,$(".class")[0],不谢

    【热门文章】
    【热门文章】