Have toggleClass disappears, but does not disappear

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 doesn’t exist. You could create your own:

$.fn.myToggleClass = function(className, showDur, hideDur) {
        this.removeClass(className, hideDur);
    } else {
        this.addClass(className, showDur);


Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 前端开发 » Have toggleClass disappears, but does not disappear

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录