JQuery uses the plug-in Lavalamp to achieve dynamic beautification of navigation bar

Source: Internet
Author: User

The plug-in Lavalamp is used to achieve the Dynamic Display Effect of the navigation bar. It was previously implemented using animate, and the effect was not very good.
Copy codeThe Code is as follows:
<Script src = "js/jquery-2.0.0.min.js" type = "text/javascript"> </script>
<Script src = "js/jquery. easing. min. js" type = "text/javascript"> </script>
<Script src = "js/jquery. lavalamp. js" type = "text/javascript"> </script>
<Script type = "text/javascript">
$ (Function (){
$ (". Nav"). lavaLamp ({
Fx: "backout ",
Velocity: 1100,
Mouseover: function (event, menuItem) {alert ();}
});
});

</Script>

<Style>

. Nav {
Width: pixel PX;
Height: 100px;
Float: left;
Position: relative;
}
. Nav li {
Width: auto;
Min-width: 40px;
Line-height: 100px;
Padding: 0 15px;
Margin: 0 10px 0 0;
Color: #000;
Font-size: 14px;
Text-align: center;
Float: left;
}
. Nav li. back {
Background: #86bf40;
-Moz-border-radius: 5px;
-Webkit-border-radius: 5px;
Line-height: 2;
Width: 40px;
Height: 100px ;/*----*/
Z-index: 1 ;/*----*/
Position: absolute ;/*----*/
Margin-top: 0px;
Margin-left: 5px;
}
. Nav li {
Color: #000;
Z-index: 2 ;/*----*/
Font-variant: small-caps;
Text-decoration: none;
Position: relative ;/*----*/
Margin: auto 10px;
}

</Style>
</Head>

<Body>
<! -- Header -->
<Div class = "headerbox">
<Div class = "header"> <a href = "http://www.uuspeed.com/" class = "logo"> </a>
<Ul class = "nav">
<Li class = "current"> <a href = "#"> first page </a> </li>
<Li class = "1"> <a href = "#"> Personal Edition </a> </li>
<Li class = "2"> <a href = "#"> medium/small version </a> </li>
<Li class = "3"> <a href = "#"> Enterprise Edition </a> </li>
<Li class = "4"> <a href = "#"> service and price </a> </li>
<Li class = "5"> <a href = "#"> about us </a> </li>
</A>
</Ul>
<Div class = "login"> <a href = "" class = "icon_login"> login </a> <a href = "" class = "icon_login"> note book </a> </div>
</Div>
</Div>


</Body>

</Html>

/// ------ Modify the lavalamp. js file --------------
Copy codeThe Code is as follows:
(Function ($ ){
$. Fn. lavaLamp = function (o ){
O = $. extend ({fx: "linear", speed: 500, click: function () {}}, o | {});


Return this. each (function (){
Var me = $ (this ),
Noop = function (el ){

},
$ Back = $ ('<li class = "back"> <div class = "left"> </div> </li>'). appendTo (me ),
$ Li = $ ("li", this ),
Curr = $ ("li. current", this) [0] | $ ($ li [0]). addClass ("current") [0];


$ Li. not (". back"). hover (function () {move (this );});


$ (". Nav li: eq (0) a" ).css ("color", "# FFF ");
Function setCurr (el) {alert (el. offsetWidth );
$Back.css ({"left": el. offsetLeft + "px", "width": el. offsetWidth + "px "});
Curr = el;

};

Function move (el ){
$ Back. each (function (){
$. Dequeue (this, "fx ");}
). Animate ({
Width: el. offsetWidth-40,
Left: el. offsetLeft
}, O. speed, o. fx, function (){
Var a0 = $ (". nav li: eq (0) ");
Var a1 = $ (". nav li: eq (1) ");
Var a2 = $ (". nav li: eq (2) ");
Var a3 = $ (". nav li: eq (3) ");
Var a4 = $ (". nav li: eq (4) ");
Var a5 = $ (". nav li: eq (5) ");
If (el. offsetLeft = 0 ){
$ (". Nav li: eq (0) a" ).css ("color", "# FFF ");
A1.css ("color", "#000 ");
A2.css ("color", "#000 ");
A3.css ("color", "#000 ");
A4.css ("color", "#000 ");
A5.css ("color", "#000 ");
}
If (el. offsetLeft = 92 ){
$ (". Nav li: eq (1) a" ).css ("color", "# FFF ");
A0.css ("color", "#000 ");
A2.css ("color", "#000 ");
A3.css ("color", "#000 ");
A4.css ("color", "#000 ");
A5.css ("color", "#000 ");
}
If (el. offsetLeft = 194 ){
$ (". Nav li: eq (2) a" ).css ("color", "# FFF ");
A1.css ("color", "#000 ");
A0.css ("color", "#000 ");
A3.css ("color", "#000 ");
A4.css ("color", "#000 ");
A5.css ("color", "#000 ");
}
If (el. offsetLeft = 296 ){
$ (". Nav li: eq (3) a" ).css ("color", "# FFF ");
A1.css ("color", "#000 ");
A2.css ("color", "#000 ");
A0.css ("color", "#000 ");
A4.css ("color", "#000 ");
A5.css ("color", "#000 ");
}
If (el. offsetLeft = 398 ){
$ (". Nav li: eq (4) a" ).css ("color", "# FFF ");
A1.css ("color", "#000 ");
A2.css ("color", "#000 ");
A3.css ("color", "#000 ");
A0.css ("color", "#000 ");
A5.css ("color", "#000 ");
}
If (el. offsetLeft = 528 ){
$ (". Nav li: eq (5) a" ).css ("color", "# FFF ");
A1.css ("color", "#000 ");
A2.css ("color", "#000 ");
A3.css ("color", "#000 ");
A4.css ("color", "#000 ");
A0.css ("color", "#000 ");
}
});
};


});

};
}) (JQuery );

See http://www.uuspeed.com/

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.