Home Ajax Jquery Creating custom animations in jQuery
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Creating custom animations in jQuery

Advertisement
This page discusses - Creating custom animations in jQuery

Creating custom animations in jQuery

     

Creating custom animations in jQuery

You can perform custom animation by using '.animate( )'  method .

Example :

In this example , we are animating a image using animate function of jQuery. We can do following things during animation using it's attribute (attributes are given inside braces):

1.Can reduce Image opacity(opacity).

2.Can reduce the height of Image(left).

3.Can shift Image position to left at a given distance(height).

animateImage.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <script type="text/javascript" src="jquery-1.4.2.js"></script>
  </HEAD>

 <BODY>
 
 <div id="clickme" >
 <font color="red">
  Click here
  </font>
</div>
<img id="book" src="images/jquery5.jpeg" alt="" width="200" height="223"
 style="position: relative; left: 10px;" /> 

<script>
$('#clickme').click(function() {
$("#targetDiv").hide();
  $('#book').animate({
    opacity: 0.25,
    left: '+=50',
    height: 'toggle'
  }, 5000, function() {
    // Animation complete.
	$("#targetDiv").html("<h3>"+ "Click again above link to animate" 
+ "</h3>").fadeIn("slow");
  });
});

</script>

<font color="blue">
<div id="targetDiv" style="display: none;"></div>
</font>
 </BODY>
</HTML>

Output :

Before Click :

After Click :

Again after 3rd click :

Download Source Code

Click here to see online demo

Learn from experts! Attend jQuery Training classes.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 18, 2011

Related Tutorials

Ask Questions?    Discuss: Creating custom animations in jQuery  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com