Animating image using JavaScript- Using JavaScript function document.getElementById() we can create simple image animation as given below:
E.g.
Check Output:
E.g.
<html>
<head>
<title>Click Image to Animate
</title>
</head>
<body>
Click Image to Animate
<br>
<img id="imageid" onclick="imgchange()"
src="img1.png">
<script>
function imgchange()
{
var image = document.getElementById("imageid");
if (image.src.match("img1"))
{
image.src = "img2.png";
}
else if(image.src.match("img2"))
{
image.src="img3.png";
}
else if(image.src.match("img3"))
{
image.src="img4.png";
}
else
{
image.src = "img1.png";
}
}
</script>
</body>
</html>
Download Codes
Related Topics:
- JavaScript Introduction
- Variables in JavaScript
- JavaScript Function
- Accessing JavaScript Function
- Creating JavaScript interactive form
- Accessing form field value
- Creating interactive form login webpage
- Networking Fundamentals
- TCP/IP and Internet addressing
- Internet Working
- Internet Working Servers
- Concept and need for web publishing
- Web languages
- Javascript Control Structure
- Checking Text is Letter/s
- Checking Text is Number/s
- Checking Textbox is Empty or not
- Addition of two numbers
- Subtraction of two numbers
- Multiplication of two numbers
- Division of two numbers
- Form field validations
- Email validation