• Home
  • New Entries
  • Popular Entries
  • Submit a Story
  • About

Fantastic Bouncy Effect using jQuery/JavaScript ...

Let us see how can we create a Bounce Effect in HTML pages using jQuery. Bounce effect is an effect which resembles bouncing of a ball on floor or on a wall. These kind of effects dramatically improve user experience.
The Goal

Our Goal will be to create a HTML page that has 4 boxes (DIVs). Clicking each of these boxes will bounce them is a particular direction. We can control the direction as well as the speed of bouncing element with arguments to the method of jQuery.


Step 1: The HTML Code

Following will be the HTML code for our example:

·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150
01.<table>
02.<tr>
03.    <td><div id="bouncy1">Click here to bounce. Direction: Up</div></td>
04.    <td><div id="bouncy2">Click here to bounce. Direction: Left</div></td>
05.</tr>
06.<tr>
07.    <td><div id="bouncy3">Click here to bounce. Direction: Right</div></td>
08.    <td><div id="bouncy4">Click here to bounce. Direction: Down</div></td>
09.</tr>
10.</table>
11.<br/>
12.<input id="bounceAll" type="button" value="Click to Bounce All!"/>


Step 2: The Stylesheet CSS Code

Just to add some color to our boxes, add following CSS code to your HTML:

·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150
01.div {
02.    padding:5px;
03.    width:150px;
04.    height:100px;
05.    text-align:center;
06.}
07.#bouncy1 {
08.    background-color:#FFEE88;
09.}
10.#bouncy2 {
11.    background-color:#EE88FF;
12.}
13.#bouncy3 {
14.    background-color:#EE8888;
15.}
16.#bouncy4 {
17.    background-color:#88EEFF;
18.}


Step 3: The jQuery/JavaScript Code

Now we will give the actual bounce effect to the demo. We will use jQuery library for this. Also we need to include jQuery UI for bounce effect. For this we will include js files from google apis. Google host the jQuery UI and jQuery core files on their server. We can directly include it from there.

·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150
1.<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
2.<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>

Also copy following code in your HTML to give final bounce effect.

·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150
01.$(function(){
02.
03.    //Add bounce effect on Click of the DIV
04.    $(#bouncy1).click(function () {
05.          $(this).effect("bounce", { times:5 }, 300);
06.    });
07.
08.    $(#bouncy2).click(function () {
09.          $(this).effect("bounce", { direction:left, times:5 }, 300);
10.    });
11.
12.    $(#bouncy3).click(function () {
13.          $(this).effect("bounce", { direction: ight, times:5 }, 300);
14.    });
15.
16.    $(#bouncy4).click(function () {
17.          $(this).effect("bounce", { direction: wouldown, times:5 }, 300);
18.    });
19.
20.    //Bounce all DIVs on click of button
21.    $("#bounceAll").click(function(){
22.        $("div").click();
23.    });
24.});


View Demo

Download

 Original Source:
http://viralpatel.net/blogs/2009/10/jquery-bounce-effect-bounce-html-js.html

AddThis Social Bookmark Button

Posted at 12:20:52 pm | Permalink | Posted in jQuery  Javascript  

Related Stuff

  • MooV: Using cutting edge Video phones and Software Video Phones - coupling all that with VoIP and empowering the disabled.

  • Moo Telecom: VoIP communications made easy - Ring anyway with the fun and ease of using a normal phone

  • TagR:Mobile Social Network with Real Time Locations Based services, and Ambience Intelligence, VoiP, IM, Skype, Googletalk, Mapping, Flickr, Events, Calendaring, Scheduling, SecondLife Support

  • ClearSMS : ClearSMS is a Web-based application that lets you send bulk SMS messages to your customers, contacts, or just about anyone.

  • Jajah:jah is a VoIP (Voice over IP) provider, founded by Austrians Roman Scharf and Daniel Mattes in 2005[1]. The Jajah headquarters are located in Mountain View, CA, USA, and Luxembourg. Jajah maintains a development centre in Israel.

  • Skype: It’s free to download and free to call other people on Skype. Skype the number one voice over ip software

  • PrivatePhone: a free local phone number with voicemail and messages you can check online or from any phone.

Top Stuff

e-messenger

MSN Web Messenger

eBuddy

ASP.NET Ajax CalendarExtender and Validation

AIM Express

Ajax Tools for ASP.NET Developers



About Ajaxlines

Ajaxlines is a project focused on providing its audience with a database of most of Ajax related articles, resources, tutorials and services from around the world.

Its purpose is to showcase the power of Ajax and to act as a portal to the Ajax development community.


Search


Topics

  • .Net (176)
  • Ajax (112)
  • Ajax Games (10)
  • Articles (95)
  • Bookmarking (35)
  • Calendar (21)
  • Chat (45)
  • ColdFusion (3)
  • CSS (84)
  • Email (23)
  • Facebook (84)
  • Flash (20)
  • Google (54)
  • Html (29)
  • Image (12)
  • International Calls & VOIP (7)
  • Java (58)
  • Javascript (280)
  • jQuery (200)
  • JSON (75)
  • Perl (2)
  • PHP (172)
  • Presentation (19)
  • Python (3)
  • Resources (2)
  • RSS (8)
  • Ruby (32)
  • Storage (4)
  • Toolkits (103)
  • Tutorials (227)
  • UI (11)
  • Utilities (174)
  • Web2.0 (18)
  • XmlHttpRequest (29)
  • YUI (13)

© 2006 www.ajaxlines.com. All Rights Reserved. Powered by IRange