效果如圖所示:
![1481788992437296.jpg jQuery實作的導覽下拉選單效果](https://img.php.cn//upload/image/218/563/291/1481788992437296.jpg)
html代碼:
jQuery代碼:
//导航效果(兼容IE6)
/*
1.使用$("#navigation ul li:has(ul)")函数来选择含有
元素的- 元素,然后为它们添加hover事件,
2.在hover事件的第一个函数内,使用$(this).children("ul")找到
- 元素内部的
元素,然后用stop(true,true)语句使导航向下扩展
3.在hover事件的第二个函数内,用stop(true,true).slideUp("fast")语句使导航向上隐藏
4.在两个动画效果之前都添加了stop(true,true)方法,这样做的好处是能把为执行完的动画队列清空,并且将正在执行的动画跳转到末状态
*/
$(function(){
$("#navigation ul li:has(ul)").hover(function(){
$(this).children("ul").stop(true,true).slideDown(400);
},function(){
$(this).children("ul").stop(true,true).slideUp("fast");
});
})登入後複製
更多jQuery實現的導航下拉式選單效果相關文章請注意PH網相關文章!