`
thinktothings
  • 浏览: 782098 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

js 菜单

    博客分类:
  • js
 
阅读更多


官网:http://www.dynamicdrive.com/dynamicindex1/ddsmoothmenu.htm#

Author: Dynamic Drive | July 17th, 11'

 

 

Updated: Dec 17th, 10" (v1.5): Updated menu shadow to use CSS3 box shadows when the browser is FF3.5+, IE9+, Opera9.5+, or Safari3+/Chrome. Only .js file changed.

Description: Smooth Navigation Menu is a multi level, CSS list based menu powered using jQuery that makes website navigation a smooth affair. And that's a good thing given the important role of this element in any site. The menu's contents can either be from direct markup on the page, or an external file and fetched via Ajax instead. And thanks to jQuery, a configurable, sleek "slide plus fade in" transition is applied during the unveiling of the sub menus. The menu supports both the horizontal and vertical (sidebar) orientation.

Some noteworthy features- You can specify a delay before the sub menus appear and disappear when the mouse rolls over and out of them, respectively. The sub menus reposition themselves if too close to the window's right edges. And last but not least, the depth of the accompanying shadow can be customized, or removed altogether. Smooth we say!

 

 


Directions Developer's View

Step 1: Insert the following code into the <head> section of your page:

Select All

The above code references a few external files, which by default you should upload to the same directory as the page itself (right click each file and select "Save As"):

Step 2:  Add the below menu code to the BODY section of your page. It contains the markup for 1 horizontal menu and 1 vertical menu:

Select All

Each menu should consist of an outer DIV and a valid UL list contained inside it.

If you wish the menu content to reside in an external file on your server and dynamically added to your page(s), read the section "Putting the Menu contents in an external file" below.

Well, that's it for installation.

ddsmoothmenu.init() and Menu content structure

Setting up a Smooth Navigational Menu on your page involves calling ddsmoothmenu.init() inside the HEAD section of your page:

ddsmoothmenu.init({
 mainmenuid: "smoothmenu1", //menu DIV id
 orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
 classname: 'ddsmoothmenu', //class added to menu's outer DIV
 //customtheme: ["#1c5a80", "#18374a"],
 contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})

where "smoothmenu1" corresponds to the menu content's outermost DIV on the page. Here's a description of each option:

Attribute Description
mainmenuid The ID of the menu's outermost DIV. If the menu contents are fetched via Ajax, then this ID should correspond to the outermost DIV that's within the external file.
orientation Sets the orientation of the menu. Enter the value "h" or "v" for a horizontal or vertical menu, respectively. Note that the "classname" setting below must also be set according to the "orientation" setting.
classname Sets the CSS class name that gets applied to the outermost DIV of the menu, effectively styling it. Based on the "orientation" setting above, you want to enter the CSS class that correctly styles the menu By default, "ddsmoothmenu" creates a horizontal menu bar, while "ddsmoothmenu-v" creates a vertical one. Take a look inside ddsmoothmenu.css and ddsmoothmenu-v.css.
customtheme In general, customizing the menu's style and background colors is done by editing the two CSS files of the script. However, you can also modify the menu's background and hover background color- on a per page or per menu basis easily, by taking advantage of the "customtheme" setting. To do so, uncomment (remove the // prefix) from this setting and declare two CSS background values, one for the default state, the other, when the mouse rolls over the menu items:

customtheme: ["#1c5a80", "#18374a"], //override default menu CSS background values? Uncomment: ["normal_background", "hover_background"]

This property is useful for quickly testing out color combinations without having to edit "ddsmoothmenu.css" each time.

contentsource Enter "markup" if your  menu contents are directly inline on the page, or ["container_id", "path_to_menu_file"] For more info on the later option, see "Putting the Menu contents in an external file and fetched using Ajax" below.

Menu content structure

As far as the HTML markup of each menu, it should consist of an outer DIV plus a valid UL list inside it, such as:

<div id="smoothmenu1">
 <ul>
 <li><a href="http://www.dynamicdrive.com">Item 1</a></li>
 <li><a href="#">Folder 0</a>
  <ul>
  <li><a href="#">Sub Item 1.1</a></li>
  <li><a href="#">Sub Item 1.2</a></li>
  </ul>
 </li>
 </ul>
</div>

Make sure the UL list is valid You can use W3C's validation service to quickly check your HTML list for incorrectly nested or unclosed tags.

Putting the Menu contents in an external file and fetched using Ajax

 

 

Instead of the menu's content being direct markup on the page, you can instead put that HTML in an external file on your server and have the menu dynamically added to the BODY of your page using Ajax. The above menu is embedded this way. The process for this is simple enough:

  1. Move the entire menu's HTML markup- including the outermost DIV container- to an external file on your server. For example: "smoothmenu.htm"
  2. On your page(s) themselves where you want the menu to be dynamically added, add an empty DIV container with a unique ID of its own in the BODY section of the page:

    <div id="smoothcontainer">
    <noscript>
    <a href="link to site map for search engines and user with JS disabled">Site map</a>
    </noscript>
    </div>

    This container's contents will be replaced by the menu contents defined in your external file when ddsmoothmenu.init() is run. You can include any HTML within this empty container that you may want shown to search engines or users with JavaScript disabled, as it will be replaced when the script is run.
  3. Finally, you need to edit ddsmoothmenu.init()'s "contentsource" setting to the appropriate setting :
     
    ddsmoothmenu.init({
    mainmenuid: "smoothmenu-ajax",
    //customtheme: ["#1c5a80", "#18374a"], //override default menu CSS background values? Uncomment: ["normal_background", "hover_background"]
    contentsource: ["smoothcontainer", "smoothmenu.htm"] //"markup" or ["container_id", "path_to_menu_file"]
    })

    The path to the external file, in this case "smoothmenu.htm", should be a relative path to it based on the current page's position within your site.

Styling the menu item the user is currently at

When the user rolls over a menu item (LI element) that contains a sub menu (UL element), the script dynamically adds a CSS class of ".selected" to the former's inner A element. This allows you to style the current active menu item differently from the rest. Inside "ddsmoothmenu.css", the relevant CSS you'll want to tweak is:

.ddsmoothmenu ul li a.selected{ /*CSS class that's dynamically added to the currently active menu items' LI A element*/
background: black;
color: white;
}

Global menu settings

Finally inside ddsmoothmenu.js there are a few global settings you can modify, such as setting the paths to the arrow images, speed of animation, and whether to disable shadows:

arrowimages: {down:['downarrowclass', 'http://www.cssdrive.com/lib/down.gif', 23], right:['rightarrowclass', 'right.gif']},
transition: {overtime:300, outtime:300}, //duration of slide in/ out animation, in milliseconds
shadow: {enable:true, offsetx:5, offsety:5}, //enable shadow?
showhidedelay: {showdelay: 100, hidedelay: 200}, //set delay in milliseconds before sub menus appear and disappear, respectively

The last line above lets you specify the delay before the sub menus appear and disappear when the mouse rolls over and out of them, respectively.

分享到:
评论

相关推荐

    s数型菜单,js+xml菜单,js+table菜单,js+div菜单,js菜单

    总的来说,选择哪种JavaScript菜单技术取决于项目需求、性能考虑以及开发者的熟练程度。在实际应用中,开发者可能会根据具体情况组合使用这些技术,以达到最佳的用户体验和性能效果。在学习和实践中,理解每种技术的...

    35个javascript菜单菜单样式

    "35个JavaScript菜单菜单样式"是一个资源包,提供了多种设计独特的菜单样式,旨在帮助开发者提升网站或应用的用户体验。 在网页设计中,菜单是一个重要的导航元素,它允许用户轻松地浏览网站的不同部分。JavaScript...

    js 菜单大全,包含了各种漂亮的菜单

    总的来说,这个“js 菜单大全”集合是一个宝贵的资源,无论你是初学者还是经验丰富的开发者,都可以从中学习到JavaScript菜单设计的各种技巧和最佳实践。通过深入理解和实践这些示例,你可以提升自己的前端开发技能...

    js 菜单js 菜单js 菜单js 菜单js 菜单

    js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js 菜单js ...

    javascript 菜单

    "Basic"可能是一个基础的JavaScript菜单,展示了最简单的下拉或弹出菜单的基本结构。这包括如何使用JavaScript操作DOM元素(如添加和删除class,显示和隐藏元素)以及响应用户事件。 4. **Drop Shadow** "Drop ...

    仿淘宝商城左侧JS菜单

    总的来说,"仿淘宝商城左侧JS菜单"项目是学习和实践前端开发技能的好案例,涵盖了CSS布局、JavaScript交互以及现代WEB开发中的诸多技巧。通过这样的实践,开发者可以提高自己在网站设计和用户体验方面的专业能力。

    Js右键菜单,js菜单,漂亮的Js右键导航,好用的Js右键菜单

    本文将深入探讨"Js右键菜单,js菜单,漂亮的Js右键导航,好用的Js右键菜单"这一主题,帮助开发者了解如何利用JavaScript实现高效、美观的右键菜单功能。 一、JavaScript右键菜单的基本原理 在网页上,右键点击事件...

    div+css+js菜单

    div+css+js菜单 div+css+js菜单 div+css+js菜单 div+css+js菜单 div+css+js菜单 div+css+js菜单 div+css+js菜单 div+css+js菜单 div+css+js菜单

    jsp的仿outlook的js菜单

    通过分析和调试这个文件,我们可以更深入地了解如何在JSP中构建仿Outlook的JavaScript菜单。 总的来说,"jsp的仿outlook的js菜单"是一个结合了JavaScript、JSP和CSS技术的项目,它展示了如何通过这些技术来创建交互...

    css+javascript 菜单

    "CSS+JavaScript 菜单"就是这样一个技术组合,用于构建动态、响应式且功能丰富的导航元素。下面将详细讲解CSS和JavaScript在创建这种菜单中的作用,以及如何将两者结合使用。 首先,CSS(Cascading Style Sheets)...

    一个很不错的Js菜单生成工具

    JavaScript(Js)是一种广泛应用于网页和网络应用的脚本语言,它主要负责处理客户端的交互逻辑,让网页更具动态性和用户友好性。在网页设计中,菜单是必不可少的一部分,它帮助用户快速导航到不同的页面或功能。而...

    13个漂亮的JS导航菜单

    首先,我们关注的是JS(JavaScript)在创建动态导航菜单中的作用。JavaScript是一种强大的客户端脚本语言,它允许开发者为网页添加交互性,使得导航菜单不仅美观,而且具有响应性和自定义功能。JS菜单通常包括下拉...

    提供一个好用的js菜单树

    JavaScript菜单树是一种基于JavaScript编程语言构建的动态导航菜单,它以树形结构展示数据,用户可以通过展开和折叠节点来查看或隐藏子级菜单。这样的设计使得大量层级关系的数据变得易于理解和操作,尤其适用于网站...

    js菜单模板

    该压缩包文件提供的“菜单js模板”包含样式代码和示例,意味着它不仅包含了JavaScript逻辑,还可能包括CSS样式,用于控制菜单的外观。通过引入这个模板,开发者无需从零开始编写菜单代码,可以节省大量时间和精力,...

    js菜单 鼠标经过折叠/滑动菜单

    在JavaScript的世界里,创建动态和交互式的用户界面是常见的需求,而“js菜单 鼠标经过折叠/滑动菜单”就是这样的一个功能。这种菜单设计可以极大地提升网站的用户体验,因为它允许用户通过简单地将鼠标悬停在菜单项...

    js菜单.rar

    总的来说,"js菜单.rar"提供的资源是一个实用的JavaScript菜单解决方案,涵盖了事件处理、DOM操作、数据持久化和动态效果等多个JavaScript核心概念。无论是初学者还是经验丰富的开发者,都能从中学习到关于...

    js菜单(sd-menu)

    JavaScript(简称JS)是一种轻量级的解释型编程...以上就是关于"js菜单(sd-menu)"的一些关键知识点,涵盖了JavaScript菜单实现的基本原理和常见实践。掌握这些技能,开发者可以创建出符合各种需求的交互式菜单系统。

    asp.net动态js菜单程序源码(动态菜单+静态菜单+数据库文件)

    资源名:asp.net动态js菜单源码(动态菜单+静态菜单+数据库文件) 资源类型:程序源代码 源码说明: 1.Default.aspx页面是框架,需要静态菜单显示或是动态菜单显示,设置起始页。Login页面或LoginStatic页面。 2.运行 ...

    js菜单[简单实用]

    在这个"js菜单[简单实用]"的项目中,我们可以看到一个基本的JavaScript菜单实现,适用于那些希望用JS来控制动态菜单的开发者。 首先,"index.html"是网页的主文件,通常包含HTML结构以及内联或外部引用的CSS和JS...

    JS菜单-横|纵向菜单

    JavaScript(简称JS)和jQuery是Web开发中用于创建交互式用户界面的重要工具,尤其是在构建菜单系统时。在本文中,我们将深入探讨如何使用这两种技术来创建高效、灵活且跨浏览器的横纵向菜单。 首先,JavaScript是...

Global site tag (gtag.js) - Google Analytics