How to fix strange slideDown() behavior or it not opening in jQuery 1.X

When you want to create, for site navigation, etc., **hover-expandable dropdown menus** or **mega dropdown menus**
You'll probably write this kind of jQuery.
$(".menu").hover(
function(){
$(".cont").stop().slideDown();
},
function() {
$(".cont").stop().slideUp();
});
Here's what I actually created. **Please hover over it**.
Menu
- Menu 1
- Menu 2
- Menu 3
- Menu 4
- Menu 5
This site's jQuery version is 3.4.0, so there's no problem, but
slideDown() and slideUp() **have bugs in jQuery version 1.X**.
This is a reproduction in jQuery 1.4. Try hovering and unhovering.
If the iframe is not displayed correctly, click here
If you repeat it, does it stop opening?
The same applies not only to the hover() event but also when using mouseenter() and mouseleave().
While it would be ideal to just use the latest jQuery, I'll introduce a workaround for cases where that's not possible.
Workaround
For jQuery 1.X, you write it like this.
$(".menu").hover(
function(){
$(".cont").css("height", "").stop().slideDown();
},
function() {
$(".cont").css("height", "").stop().slideUp();
});
Reset the height before .stop().
Then...
This is a reproduction in jQuery 1.4.
It might be a bit strange if you click rapidly, but it's better than not being able to open it at all, isn't it?
If the iframe is not displayed correctly, click here
Upon investigation, it seems that similar processing is required for jQuery 1.0 to 1.9.
If this still doesn't work, or if you know a better method, please let me know in the comments!




If this was helpful, we appreciate your support!
Any support received will be used for childcare.
Or support us by buying something from the buttons below
(You don't have to buy the linked product.)
Amazon
楽天市場
Yahoo!ショッピング
PR