CSS Fast navigation pull-down menu animation effect

Source: Internet
Author: User
Tags wrapper

This is a special effect of the Pull-down navigation menu with deformable animation effects. When the navigation menu switches between menu items, the Drop-down menu quickly changes dynamically depending on the size of the menu's contents, displaying the appropriate Drop-down menu size, and the effect is great.


Html

The HTML structure of the navigation menu is as follows:

<a href= "#0" class= "Nav-trigger" >open nav<span aria-hidden= "true" ></span></a>

<nav class= "Main-nav" >
<ul>
<li class= "Has-dropdown Gallery" data-content= "about" >
<a href= "#0" >About</a>
</li>

<li class= "Has-dropdown links" data-content= "pricing" >
<a href= "#0" >Pricing</a>
</li>

<li class= "has-dropdown button" data-content= "Contact" >
<a href= "#0" >Contact</a>
</li>
</ul>
</nav>

<div class= "Morph-dropdown-wrapper" >
<div class= "Dropdown-list" >
<ul>
<li id= "About" class= "dropdown gallery" >
<!--dropdown content here-->
</li>

<li id= "Pricing" class= "dropdown links" >
<!--dropdown content here-->
</li>

<li id= "Contact" class= "dropdown button" >
<!--dropdown content here-->
</li>
</ul>

<div class= "Bg-layer" aria-hidden= "true" ></div>
</div> <!--dropdown-list-->
</div> <!--morph-dropdown-wrapper-->

CSS style please refer to the Css/style.css file in the source code.
Javascript

To implement this navigation menu, a Morphdropdown object is created in the effect. and use the Bindevents () method to handle the element's events.
function Morphdropdown (Element) {
This.element = element;
This.mainnavigation = This.element.find ('. Main-nav ');
This.mainnavigationitems = This.mainNavigation.find ('. Has-dropdown ');
This.dropdownlist = This.element.find ('. Dropdown-list ');
//...

This.bindevents ();
}
The Bindevents () method is used to detect mouse entry and mouse exit events on the. Has-dropdown and. Dropdown elements.
morphDropdown.prototype.bindEvents = function () {
var self = this;

This.mainNavigationItems.mouseenter (function (event) {
Hover over one of the Nav items-> Show dropdown
Self.showdropdown ($ (this));
}). MouseLeave (function () {
If not hovering over a nav item or a dropdown-> hide dropdown
if (Self.mainNavigation.find ('. Has-dropdown:hover '). Length = = 0 && self.element.find ('. Dropdown-list:hover ') ). Length = = 0) self.hidedropdown ();
});

//...
};
The Showdropdown method is used to handle the Translatex values of the width, height, and. Dropdown-list elements, and to magnify and shrink the. Bg-layer element.
MorphDropdown.prototype.showDropdown = function (item) {
var selecteddropdown = this.dropdownList.find (' # ' +item.data (' content ')),
Selecteddropdownheight = Selecteddropdown.innerheight (),
Selecteddropdownwidth = Selecteddropdown.children ('. Content '). Innerwidth (),
Selecteddropdownleft = Item.offset (). Left + item.innerwidth ()/2-selecteddropdownwidth/2;

Update dropdown and dropdown background position and size
This.updatedropdown (Selecteddropdown, parseint (selecteddropdownheight), Selecteddropdownwidth, ParseInt ( Selecteddropdownleft));

Add the. Active class to the selected dropdown and is-dropdown-visible to the. Cd-morph-dropdown
//...
};

MorphDropdown.prototype.updateDropdown = function (dropdownitem, height, width, left) {
This.dropdownList.css ({
'-moz-transform ': ' Translatex (' + left + ' px '),
'-webkit-transform ': ' Translatex (' + left + ' px '),
'-ms-transform ': ' Translatex (' + left + ' px '),
'-o-transform ': ' Translatex (' + left + ' px '),
' Transform ': ' Translatex (' + left + ' px '),
' Width ': width+ ' px ',
' Height ': height+ ' px '
});

This.dropdownBg.css ({
'-moz-transform ': ' ScaleX (' + width + ') scaleY (' + height + ') ',
'-webkit-transform ': ' ScaleX (' + width + ') scaleY (' + height + ') ',
'-ms-transform ': ' ScaleX (' + width + ') scaleY (' + height + ') ',
'-o-transform ': ' ScaleX (' + width + ') scaleY (' + height + ') ',
' Transform ': ' ScaleX (' + width + ') scaleY (' + height + ') '
});
};

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.