我要在移動端實現點擊按鈕顏色變化的(類似pc的hover效果)效果,點擊后顏色變化停留一秒鐘,然后變回去?第一種方法var icon_timer;$('.nav li .glyphicon-menu-down').on('click', function(e) { if ($(window).width() < 991) { $(this).addClass('touch-hov'); clearTimeout(icon_timer); icon_timer = setTimeout(function() {$(this).removeClass('touch-hov')},1000); }});發現settimeout中的的removeclass總是不執行?第二種方法$('.nav li>div').on('touchstart click', function(e) { if ($(window).width() < 991) { e.stopPropagation(); $(this).addClass('touch-hov'); clearTimeout(div_timer); }});$('.nav li>div').on('touchend', function() { div_timer = setTimeout(function() {$(this).removeClass('touch-hov')},1000);});使用這種方法有時不進入touchend事件,進去了 setTimeout也不執行?不知道是什么原因造成的?
js使用setTimeout不執行?
達令說
2019-02-12 17:12:30