Home Ajax Jquery Animate image in jQuery

Related Tutorials


 
 

Share on Google+Share on Google+

Animate image in jQuery

Advertisement
Animate image using jQuery can be performed via a .animate() method. In this article, we have discussed how to change the size of image on button click in jQuery.

jQuery provides several methods to implement different kinds of effects in a simple HTML page. jQuery is basically a JavaScript library that simplifies the JavaScript work.

Here we takes a small example, that will resize the image on click. If you see the code carefully, you'll find how crucial is the .animate() method is, in jQuery.

It helps you to change the size of an images on click. Here is the examples of an image animations that changes its width and height attributes with jQuery animate function.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Animate Div in Jquery</title>
<style>
div {
background-color: #abc;
width: 400px;
border: 1px solid red;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<script>
$(document).ready(function () {
var large={width: "185px",height: "250px"};
var small={width: "400px",height: "232px"};
var count=1; 
$("#image").click(function () { 
(count==1)?$(this).animate(large):$(this).animate(small);
count = 1-count;
})
});
</script>
</head>
<body>
<div>Click Image to change the image Size.</br>
<img src="bridal.jpg" id="image" /></div>
</body>
</html>
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: December 29, 2013

Related Tutorials

Discuss: Animate image in jQuery  

Post your Comment


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