Have toggleClass fade in but not fade out

I am currently using the `toggleClass()` method with jQuery and I'd like to have the class fade in, but I don't want it to fade out. I've been using the "duration" attribute, but given that it is toggleClass, the duration is the same both ways. I don't want to use `addClass()` with a fade in and `removeClass()` without a fade out because I feel like the code will get too lengthy and unruly. I want small, simple, readable code. Any ideas? I have this so far: $("#e" ).hover(function() { $(this).closest("#word").toggleClass("hoverE", 500 ) }); I would like something like this where I can specify fade in duration and fade out duration: $("#e" ).hover(function() { $(this).closest("#word").toggleClass("hoverE", 500, 0 ) }); I've tried something like this, but it doesn't work: $("#e" ).hover(function() { $(this).closest("#word").toggleClass("hoverE").fadeIn(500) }); **HTML:**

H

E

L

L

O


I assume that you are using jquery ui, as toggleClass normally doesn't have a duration.

以上就是Have toggleClass fade in but not fade out的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏