简体   繁体   English

setTimeout不能在移动Safari上间歇性地工作吗?

[英]setTimeout doesn't work intermittently on mobile Safari?

$('.btn-activate').on('click touchstart', function() {
        $('.discount').each(function() {
            var $this = $(this);
            $({ countNum: parseInt($this.html())}).animate({
                    countNum: couponPercentage
                },
                {
                    duration: 1000,
                    easing:'linear',
                    step: function() {
                        $this.html(Math.floor(this.countNum) + '% OFF');
                    },
                    complete: function() {
                        $this.html(Math.floor(this.countNum) + '% OFF');
                        refreshIntervalId = setInterval(function() {
                            if ($this.css('visibility') == 'hidden') {
                                $this.css('visibility', 'visible');
                            } else {
                                $this.css('visibility', 'hidden');
                            }
                        }, 200);

                        setTimeout(function(){
                            clearInterval(refreshIntervalId);
                            if ($this.css('visibility') == 'hidden') {
                                $this.css('visibility', 'visible');
                            }
                        }, 2000);
                    }
                });
        });
    })

In the complete block, a blinking animation is attempted to be achieved. complete块中,尝试实现闪烁的动画。 This works, but on Safari Mobile there are times when the setTimeout doesn't seem to work because the blinking animation doesn't stop. 这可以工作,但是在Safari Mobile上,有时setTimeout似乎不起作用,因为闪烁的动画不会停止。

Apparently this had something to do with using .on('click touchstart',...) . 显然,这与使用.on('click touchstart',...)

There is some sort of double triggering happening when the user taps on the button. 当用户点击按钮时,会发生某种双重触发。 After removing the redundant touchstart , I'm no longer able to replicate this. 删除冗余的touchstart ,我将不再能够复制它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM