社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Jquery

如何向jQuery.addClass和.removeClass添加延迟?

twelvell • 5 年前 • 1812 次点击  

我需要加一个 延迟 200ms 在这里:

jQuery('.class').hover(() => jQuery('#custom').addClass('addedclass'), () => jQuery('#custom').removeClass('addedclass'));

jQuery: Can I call delay() between addClass() and such? 但那里的结构略有不同。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/54339
 
1812 次点击  
文章 [ 1 ]  |  最新文章 5 年前
Phong
Reply   •   1 楼
Phong    5 年前

你可以用 setTimeout 去实现它。

jQuery('.class').hover(
() => setTimeout(() => jQuery('#custom').addClass('addedclass'), 200), 

() => setTimeout(() => jQuery('#custom').removeClass('addedclass'), 200));
.addedclass{
color: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="class">
  <p id="custom">Text</p>
</div>