JQuery-like Flash-beating buttons

Source: Internet
Author: User

The following small example is inspired by Baidu's application (which does not seem to have been available now), that is, when the mouse is moved up and removed, the icon will be slowed down. The effect is no worse than that of flash.

Recommended topics for BKJIA: jQuery from getting started to proficient in jQuery powerful plug-in Parade

Below is: the icons are well designed, so we will not teach you how to design them here.

The following is the JQ code:

 
 
  1. $ (Function (){
  2. // Append img to LI
  3. $ ("# Nav-shadow li"). append ('
  4. Width = "60" height = "32" alt = ""/> '); // This is a shadow image.
  5. // Append hover event
  6. $ ("# Nav-shadow li"). hover (function (){
  7. // Define e for tihs
  8. Var $ e = this;
  9. $ ($ E). find ("a"). stop (). animate ({marginTop: '-14px'}, 250, function () {// callback function control
  10. $ ($ E). find ("a"). animate ({marginTop: '-10px'}, 250 );
  11. });
  12. $ ($ E ). find ("img. shadow "). stop (). animate ({width: "80%", opacity: "0.3", marginLeft: "8px"}, 250 );
  13. }, Function (){
  14. Var $ e = this;
  15. $ ($ E). find ("a"). stop (). animate ({marginTop: "4px"}, 250, function (){
  16. $ ($ E). find ("a"). animate ({marginTop: "0px"}, 250 );
  17. });
  18. $ ($ E ). find ("img. shadow "). stop (). animate ({width: "100%", opacity: "1", marginLeft: "0px"}, 250 );
  19. }
  20. )
  21. })

Analysis:

First, add reflection:

 
 
  1. $("#nav-shadow li").append('
  2. width="60" height="32"  alt="" />') 

Then register the hover event and use the callback function to control the effect of the event. The Shadow distance is controlled by transparency.

The following is the HTML code:

 
 
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">   
  2.   
  3.      
  4.          <meta http-equiv="Content-Type" content="text/html; charset=utf-8">   
  5.          <title>button_effect</title>   
  6.          <script type="text/javascript" src="jquery-1.4.2.min.js"></script>   
  7.          <script type="text/javascript" src="action.js"></script>   
  8.          <style type="text/css">   
  9.              *{ margin:0; padding:0;}  
  10.              div{ width:500px; height:500px; margin:100px 0 auto;}  
  11.              ul,ol{ list-style:none; list-style-type:none;}  
  12.              a,a:visited,a:hover{ display:block; text-decoration:none; color:#ccc; text-indent:-9999px; 
  13. outline: 0 none; width:61px; height:60px; z-index:2; overflow:hidden;  position:relative;}  
  14.              li{ float:left; width:61px; height:92px; margin-left:10px; position:relative;}      
  15.              #nav-shadow li.chang-one a{ background:url(images/button_pic.jpg) no-repeat left top;}  
  16.              #nav-shadow li.chang-two a{background:url(images/button_pic.jpg) no-repeat -60px top;}  
  17.              #nav-shadow li.chang-three a{background:url(images/button_pic.jpg) no-repeat -120px top;}  
  18.              #nav-shadow li.chang-four a{background:url(images/button_pic.jpg) no-repeat -180px top;}  
  19.              #nav-shadow li.chang-five a{background:url(images/button_pic.jpg) no-repeat -240px top;}  
  20.              #nav-shadow li img.shadow{margin:0 auto; position:absolute; bottom:0px; left:0px; z-index:1;}  
  21.          </style>  
  22.      
  23.      <body>  
  24.       <div id="content">  
  25.           <ul id="nav-shadow">  
  26.               <li class="chang-one"><a href="#" title="reflaction_one">click me</a></li>  
  27.              <li class="chang-two"><a href="#" title="reflaction_two">click me</a></li>  
  28.              <li class="chang-three"><a href="#" title="reflaction_three">click me</a></li>  
  29.              <li class="chang-four"><a href="#" title="reflaction_four">click me</a></li>  
  30.              <li class="chang-five"><a href="#" title="reflaction_five">click me</a></li>          
  31.           </ul>  
  32.       </div>  
  33.      </body>  
  34.  

When using it, you only need to design a nice icon.

New Source Code download: Download

Link: http://www.cnblogs.com/blacksheep/archive/2011/04/13/2014416.html

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.