I'm currently working with jQuery's toggleClass()
method and I want to achieve a fade-in effect without the corresponding fade-out animation. Using the "duration" attribute applies the same duration for both actions, which is not what I want. I would like to avoid using addClass()
for fade in and removeClass()
for fade out separately as it could lead to lengthy and messy code. My goal is to keep the code simple, concise, and easy to read.
Do you have any suggestions?
This is what I've tried so far:
$("#e" ).hover(function() {
$(this).closest("#word").toggleClass("hoverE", 500 )
});
I envision something like this where I can set distinct durations for fade in and fade out:
$("#e" ).hover(function() {
$(this).closest("#word").toggleClass("hoverE", 500, 0 )
});
I experimented with this approach, but unfortunately, it didn't work:
$("#e" ).hover(function() {
$(this).closest("#word").toggleClass("hoverE").fadeIn(500)
});
HTML:
<div id="word">
<h1><a id="h" class= "letter" href=#>H</a></h1>
<h1><a id="e" class= "letter" href=#>E</a></h1>
<h1><a id="l" class= "letter" href=#>L</a></h1>
<h1><a id="l2"class= "letter" href=#>L</a></h1>
<h1><a id="o" class= "letter" href=#>O</a></h1>
</div>