在看了 https://segmentfault.com/p/12... 關于節流,去抖的文章后,發現項目中有個位置還比較適合用debounce來解決于是決定嘗試,但是去抖是ok了,發現出現個新的問題一直沒想明白想請教一下;具體就是項目中有位置顯示 各種聯系方式(微信,QQ,電話),當鼠標移入其中某一個時會展現對應的號碼,移出后則消失,加完去抖的代碼后發現只要快速在三個間移動可能會出現,最后移出的那個聯系方式不會消失的問題。相關代碼<script type="text/javascript">
$(function() {
$('.service_action_btn').hover(function() { var id_str = $(this).data('id');// #contact_qq
debounce(showContact, $(id_str));
}, function() { var id_str = $(this).data('id');// contact_qq
debounce(hideContact, $(id_str));
});
}); function debounce(method, context) {
clearTimeout(method.tId);
method.tId = setTimeout(function() {
method.call(context);
}, 500);
} function showContact() { this.show();
} function hideContact() { this.hide();
}</script>
Java Script去抖的問題
叮當貓咪
2018-08-18 20:11:54