jquery implementation Horizontal Vertical pull-down menu

Source: Internet
Author: User

LearningJavaScriptmentioned in the building of their ownJavaScriptlibraries, such asJQuery, these libraries contain their usual handy small functions that make their code clearer and easier to understand when others call it, and of course there are some issues to be aware of when writing a library, such as case, parentheses, wrapping, and so on.JQueryLearning provides some foundation,JQuerylearning mainly through a few examples to understandJQuerythe application, by viewingAPIuse specific methods to achieve their own effect, it makes the Web page move up. How the code implements a horizontal and vertical pull-down menu effect.

First inHTMLthrough theuland theLirepresents a menu item in a page, and then adds theCSSand theJSa reference to a file, noteJSReferences are referenced firstJquery.jsand then I wrote it myself.JSfile.

CSS section:

ul,li{/    * Clear menu item dot */   list-style:none;} ul{/   * Clears the indent value of the submenu */   padding:0;   margin:0;}. main,.hmain{   Background-image:url (.. /images/title.gif);   Background-repeat:repeat-x;   width:120px;} li{  background-color: #CCCCCC;} a{/   * Remove all underscores */   text-decoration:none;   padding-left:20px;   Display:bloock;   Display:inline-block;   width:100px;   padding-top:3px;   padding-bottom:3px;}. Main A,.hmain a{    color: #FFFFFF; Background-image:url (.. /images/collapsed.gif); background-repeat:no-repeat;background-position:3px Center;}. Main Li a,.hmain li a{    color: #000000; background-image:none;}. Main Ul,.hmain ul{   Display:none;}. hmain{   Float:left;   margin-right:1px;}

Menu.js section:

//portrait menu click Implementation Dropdown $ ( Document). Ready (function () {$ (". Main>a"). Click (function () {///Find the main menu corresponding to the submenu item var ulnode=$ (this). Next ("ul");/*if (      ULNODE.CSS ("display") = = "") {ulnode.css ("display", "block"); Changeicon ($ (this));        }ELSE{ULNODE.CSS ("Display", "none"); Changeicon ($ (this));} */Ulnode.slidetoggle ();//slidetoggle method is similar to toggle (hide the displayed element directly, hide the element display) Changeicon ($ (this));}); /Landscape Menu The mouse is implemented by pulling down (". Hmain"). Hover (function () {$ (this). Children ("ul"). Slidedown (); Changeicon ($ (this). Children ("a")); <span style= "Font-family:simsun;" >},function () {</span> 
  $ (this). Children ("ul"). Slideup ();   Changeicon ($ (this). Children ("a"));     }); /Modify the main menu's indicator icon function Changeicon (mainnode) {if (Mainnode) {if (Mainnode.css ("Background-image"). IndexOf (" Collapsed.gif ") >=0) {mainnode.css (" background-image "," url (' images/expanded.gif ') ");} Else{mainnode.css ("Background-image", "url (' images/collapsed.gif ')");}}}


This stage of learning is to be more hands-on, learn to view the document, mastered the method, some effect of the implementation of the same, otherwise their study is very thin, more research, do a accumulate.

jquery implementation Horizontal Vertical pull-down menu

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.