We love Web 2.0

Your own voice on the web

Everyone can write & share

                                                   Blog
Explore My Blog Explore My Blog





Social Media & Social Media Marketing
 





 Social Networking





Web Development, SEO & Online Marketing
 
   
  Bookmark and Share
  
Jquery Animated Buttons using CSS
      
Aug
30
Jamal Ahmad

jam05pgs

3 Comments  |   6361 Hits
Tags:   jquery animated buttons
 

If you use Skype I am sure that you noticed that animated button for adding more people to a chat. When you click on it the icon on the left "jumps" for a few times. I love that animation. And that's why I'm going to show you how to create the same button using jQuery and some simple CSS.

If you are not sure what button am I talking about, image below might help you.

jquery animated buttons using css

Ok, the task here is quite simple - I want the icon to jump for a few times when I hover the button. (In Skype window this icon jumps when you click on it, but I think it would be much better to have it jump on hover)

The button itself consist of an image and text placed inside of a link.

<a class="button" href="#">
    <img src="button.png" alt="" />Send info</a>
    or <a href="#">cancel</a>

Let's style the button. CSS code for this is simple and won't go through all the classes here. The key is that the icon is absolutely positioned inside its relatively positioned container - the link. The position of the icon is set to simulate Skype button, and that is to cover the left side of the button. Please note that you will see the rounded corners on the button only in Firefox thanks to -moz-border-radius- properties.

.button {
    padding: 4px 10px 3px 25px;
    border: solid 1px #8AB134;
    position: relative;
    cursor: pointer;
    display: inline-block;
    background-image: url( 'bkg.png' );
    background-repeat: repeat-x;
    font-size: 11px;
    height: 16px;
    text-decoration: none;
    color: #40740D;
    -moz-border-radius-bottomleft: 5px;
    -moz-border-radius-bottomright: 5px;
    -moz-border-radius-topleft: 5px;
    -moz-border-radius-topright: 5px;
}
.button img {
    position: absolute;
    top: -4px;
    left: -12px;
    border: none;
}
.button:hover {
    color: #8AB134;

Now the animation. We have three jumps on original Skype button - one large and two small jump. In first jump, icon will go up for 6px, in second 3px and in the last jump 2px. After each jump, the icon will go back to its original position defined in CSS. I guess it is pretty much similar to the Skype button.

$(document).ready(function(){
    $(".button").hover(function(){
        $(".button img")
            // first jump 
            .animate({top:"-10px"}, 200).animate({top:"-4px"}, 200)
            // second jump
            .animate({top:"-7px"}, 100).animate({top:"-4px"}, 100)
            // the last jump
            .animate({top:"-6px"}, 100).animate({top:"-4px"}, 100);
    });
});

Code is tested in Firefox, Safari and IE7. If this doesn't work in IE6, I simply don't care.

Now try the demo, download the source code and enjoy styling your new buttons!.

View live demo

Download source code

[ Stumble Upon ] [ Facebook ] [ del.icio.us ] [ furl ] [Sphinn] [ Digg ] [ Twitter ] [ Technorati ] [ Reddit ] [ Subscribe To RSS Feeds ]

3

 
 
Buu

Monday, August 31, 2009 @ 02:46 PM

 

that looks scary in Opera 10.0, the button gets sliced

 
Buu

Monday, August 31, 2009 @ 02:55 PM

 

I changed display: inline-block to display: inline in .button, that way it works fine in Opera too

 
Jonathan

Wednesday, April 14, 2010 @ 08:13 AM

 

Jamal, thanks a lot for this tutorial. I have a question regarding the js code. Where and How do I insert the code?. By the way I'm using a child theme in wordpress and trying to get this button to work in the sidebar. Could you please help me?.

 
   
 
Leave your comments
 
  Your comments  

     
name  

     
  email  

     
website    

     
5 + 3 =    

     
   
     

 

 

Follow me on twitter

Follow me on facebook

 

 
   

   

affiliate_link

   

affiliate_link

   

Buy Now - PayPal

   
 
   
  Blog Community
 
 
tissa
darrenrowse
amour
niculae
sassyqarla
summerzeet
electrostar
good-pens
kh
travelhotelworld
tunyalitk
masterartrep
dain22
bloggersun
jameslove4enao
thebeespace
majalahpatani
caryngf
wonkapromotions
jam05pgs
 
  View more bloggers   Join Community
   
   
  Popular Posts
 
 
JQuery Beautiful Image Slide Show in New Way
Good Pens, Saturday 18th April 2009

How 24 Hours of Work Will Send Millions of Readers to My Blog
Darren Rowse, Thursday 4th December 2008

Ajax Animated Live Search
Tunya Litk, Monday 4th May 2009

JQuery Autocomplete with Ajax PHP and MySQL
Jamal Ahmad, Sunday 14th June 2009

How to make $3000 with Free Niche Websites blueprint
Jamal Ahmad, Thursday 10th June 2010
   
   
  ExploreMyBlog Poll
 
 

Is Bing a better search engine than Google?

 

Yes

No
Unsure
 

 
   
  Blog Categories
 
 
About Blogging
Affiliate Marketing
AJAX
Banners
Blog Directories
Blog Marketing
Browsing
Copy Writing
CSS
E-Commerce
Email Marketing
Forms
Google AdSense AdWords
JQuery
Marketing Tools and Tips
Online Advertising
Online Marketing
Online Newsletter
Pay Per Click Strategy
RSS Feed Strategy
Search Engine Optimization
Social Media
Social Networking
Web 2.0
Website Analysis and Stats
Website Designing
Website Traffic
   
   
   

 

 

 

 

© Copyright Explore My Blog 2009, all rights reserved
A company registered in north America, Europe, Asia and Middle East as Explore Group.