找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
积分等级发帖收益的说明江阴论坛帮助汇总江阴论坛管理规则(必看)江阴论坛版主招聘中江阴论坛已运行
查看: 2282|回复: 0

[技术分享] jQuery 导航菜单

[复制链接]
发表于 2010-4-3 11:14:08 | 显示全部楼层 |阅读模式
二级导航菜单

鼠标划过显示菜单, 离开隐藏菜单, 没有能比这个跟简单的了.
  1. jQuery(document).ready(function(){
  2.         // 找到所有菜单, 并添加显示和隐藏菜单事件
  3.         jQuery('#menus > li').each(function(){
  4.                 jQuery(this).hover(

  5.                         // 显示菜单
  6.                         function(){
  7.                                 jQuery(this).find('ul:eq(0)').show();
  8.                         },

  9.                         // 隐藏菜单
  10.                         function(){
  11.                                 jQuery(this).find('ul:eq(0)').hide();
  12.                         }

  13.                 );
  14.         });
  15. });
复制代码
淡出淡入导航菜单

鼠标悬停显示淡入显示菜单, 离开淡出隐藏菜单. 需要加上延迟处理, 原因请参考请参考如下文章.
  1. // 线程 IDs
  2. var mouseover_tid = [];
  3. var mouseout_tid = [];

  4. jQuery(document).ready(function(){
  5.         jQuery('#menus > li').each(function(index){
  6.                 jQuery(this).hover(

  7.                         // 取消淡出菜单的线程, 延时淡入菜单
  8.                         function(){
  9.                                 var _self = this;
  10.                                 clearTimeout(mouseout_tid[index]);
  11.                                 mouseover_tid[index] = setTimeout(function() {
  12.                                         jQuery(_self).find('ul:eq(0)').fadeIn(200);
  13.                                 }, 400);
  14.                         },

  15.                         // 取消淡入菜单的线程, 延时淡出菜单
  16.                         function(){
  17.                                 var _self = this;
  18.                                 clearTimeout(mouseover_tid[index]);
  19.                                 mouseout_tid[index] = setTimeout(function() {
  20.                                         jQuery(_self).find('ul:eq(0)').fadeOut(200);
  21.                                 }, 400);
  22.                         }

  23.                 );
  24.         });
  25. });
复制代码
滚动导航菜单

鼠标悬停显示滚动展开菜单, 离开滚动卷起菜单. 需要加上延迟处理, 原因同淡出淡入导航菜单的处理.
  1. // 线程 IDs
  2. var mouseover_tid = [];
  3. var mouseout_tid = [];

  4. jQuery(document).ready(function(){
  5.         jQuery('#menus > li').each(function(index){
  6.                 jQuery(this).hover(

  7.                         // 取消卷起菜单的线程, 延时展开菜单
  8.                         function(){
  9.                                 var _self = this;
  10.                                 clearTimeout(mouseout_tid[index]);
  11.                                 mouseover_tid[index] = setTimeout(function() {
  12.                                         jQuery(_self).find('ul:eq(0)').slideDown(200);
  13.                                 }, 400);
  14.                         },

  15.                         // 取消展开菜单的线程, 延时卷起菜单
  16.                         function(){
  17.                                 var _self = this;
  18.                                 clearTimeout(mouseover_tid[index]);
  19.                                 mouseout_tid[index] = setTimeout(function() {
  20.                                         jQuery(_self).find('ul:eq(0)').slideUp(200);
  21.                                 }, 400);
  22.                         }

  23.                 );
  24.         });
  25. });
复制代码
原文:http://www.neoease.com/wordpress-menubar-6/
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|江阴人家

GMT+8, 2024-4-23 20:47 , Processed in 0.017319 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表