JQuery drop down bobs up and down continuously
I am using jquery to hide/show an DIV on hover of an LI. When I do this the div appeared but pops up and down without stopping until I take my mouse off the LI.
$(document).re开发者_运维知识库ady(function () {
$('li.menu_head').mouseover(function () {
$('div.newsadviceDrop').slideToggle('medium');
});
});
Try:
$(document).ready(function () {
$('li.menu_head').hover(function () {
$('div.newsadviceDrop').slideToggle('medium');
});
});
EDIT: To keep it open until you mouse over again do this
$(document).ready(function () {
$('li.menu_head').mouseenter(function () {
$('div.newsadviceDrop').slideToggle('medium');
});
});
Try to use .mouseenter instead of .mouseover
While the mouse is over li.menu_head, you will repeatedly call .slideToggle, which explains why you see the continuous behaviour. You could perhaps replace this with behaviour on mouseenter and mouseexit.
There is an issue like that with "mouseover".
Try "mouseenter" instead...
OR...
just use the jQuery hover()
EDIT:
silent1mezzo submitted the best/correct answer first.
加载中,请稍侯......
精彩评论