fadeIn()实现弹出下拉菜单,下拉菜单里实现鼠标覆盖二级栏目样式变化的效果。
具体见此网站
鼠标在二级菜单列表上移动时不停闪动。
据我猜测,每次触发二级栏目样式变化都会再次触发fadeIn()效果,因为在二级栏目上快速移动鼠标就不会那么明显
$(document).ready(function () {
//一级栏效果
$(".navListLi").mouseover(function(){
$(this).css({'background-color':'#ffffff'});
$(this).children().css({'color':'#00A3ED'});
$(this).children().eq(1).fadeIn();
});
$(".navListLi").mouseout(function(){
$(this).css({'background-color':'#00A3ED'});
$(this).children().css({'color':'#ffffff'});
$(this).children().eq(1).stop();//停止当前正在运行的动画
$(this).children().eq(1).hide();
});
//二级栏目效果
$(".navChildLi").mouseover(function(){
$(this).css({'background-color':'#00A3ED'});
$(this).children().css({'color':'#ffffff'});
});
$(".navChildLi").mouseout(function(){
$(this).css({'background-color':'#ffffff'});
$(this).children().css({'color':'#00A3ED'});
});
});
顺便想请教一下实现类似这样弹出效果的具体思路,
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
.navChildLi a{
补充更新:
大致的意思就是子菜单的弹出要依靠li中的a触发;收回二级菜单依靠触发其他一级菜单的a或者鼠标leave二级菜单;大致就是这个意思;下面是个完整的例子~PO主测试的时候别忘了引入JQ~
因为你的子元素同样会触发mouse事件,冒泡到父元素后事件处理程序重复的fadeIn和hide,导致闪烁。
你可以用mouseout的relatedTarget属性来判定,如果鼠标仍然在二级菜单上,就不冒泡到父元素。
二级菜单直接给css加个:hover就可以了,不用JS去实现。
涉及这种父子元素的事件绑定,记住一条原则,不要自以为的去给某个元素添加事件,而是要去判断当前目标,然后再做出动作!!!!