cuốn sách gpt4 ai đã làm

javascript - 阻止 $(this) 元素上的事件

In lại Tác giả: Walker 123 更新时间:2023-11-28 15:01:04 30 4
mua khóa gpt4 Nike

一些给定的 HTML 文章,例如:




Content





与一些基本的 Jquery 结合使用,例如:

$(".some_wrapper").mouseenter(function(){
$(this).find(".info").fadeIn(500);
});

$(".some_wrapper").mouseleave(function(){
$(this).find(".info").fadeOut(500);
});

问题:如果用户将鼠标从 .some_wrapper 快速移动到另一个,事件处理程序会多次触发并构建 fadeIn()fadeOut() 效果。只要处理程序经常触发,即使鼠标已经在容器外静止不动,这些情况也会发生。

如何防止 $(this) 元素上发生 mouseenter()mouseleave() 事件,其中 .info 可见。或者打破队列?

Cảm ơn.

câu trả lời hay nhất

在触发fadeIn或Out事件之前需要使用stop()函数

$(".some_wrapper").mouseenter(function(){
$(this).find(".info").stop().fadeOut(500);
$(this).find(".info").fadeIn(500);
});

$(".some_wrapper").mouseleave(function(){
$(this).find(".info").stop().fadeIn(500);
$(this).find(".info").fadeOut(500);
});

这将停止所有先前触发的事件并执行最新的事件。因此不会发生重复。

关于javascript - 阻止 $(this) 元素上的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40889187/

30 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress