JavaScript Animation
The HTML Code
The JavaScript Code
The Entire Code
With Javascript, we can create animated images.
The trick is let a JavaScript change between different images on different events.
The HTML Code
<a href="http://www.w3schools.com" target="_blank">
<img border="0" alt="visit w3schools!" src="b_pink.gif" id="b1" onmouseOver="mouseOver()" onmouseOut="mouseOut()"/></a>
we have given the image an id,
to make it possible for javascript to address it later.
The onMouseOver event tells the browser that once a mouse is rolled over the image,
the browser should execute a function that replaces the image with another image.
The onMouseOut event tells the browser that once a mouse is rolled away from the image,
another Javascript function should execute. This function inserts the original image agine.
The JavaScript Code
<script type="text/javascript">
functin mouseOver()
{
document.getElementById("b1").src="b_blur.gif";
}
function mouseOut()
{
document.getElementById("b1").src="b_pink.gif";
}
</script>
The function mouseOver() causes the image to shift to "b_blur.gif"
The function mouseOut() causes the image to shift to "b_pink.gif"
The Entire Code
<html>
<head>
<script type="text/javascript">
function mouseOver()
{
document.getElementById("b1").src="b_blue.gif";
}
function mouseOut()
{
document.getElementById("b1").src="b_pink.gif";
}
</script>
</head>
<body>
<a href="http://www.w3schools.com" target="_blank">
<img border="0" alt="visit w3schools!" src="b_pink.gif" id="b1" width="26" height="26" onmouseOver="mouseOver()" onmouseout="mouseOut()"/></a>
</body>
</html>
The HTML Code
The JavaScript Code
The Entire Code
With Javascript, we can create animated images.
The trick is let a JavaScript change between different images on different events.
The HTML Code
<a href="http://www.w3schools.com" target="_blank">
<img border="0" alt="visit w3schools!" src="b_pink.gif" id="b1" onmouseOver="mouseOver()" onmouseOut="mouseOut()"/></a>
we have given the image an id,
to make it possible for javascript to address it later.
The onMouseOver event tells the browser that once a mouse is rolled over the image,
the browser should execute a function that replaces the image with another image.
The onMouseOut event tells the browser that once a mouse is rolled away from the image,
another Javascript function should execute. This function inserts the original image agine.
The JavaScript Code
<script type="text/javascript">
functin mouseOver()
{
document.getElementById("b1").src="b_blur.gif";
}
function mouseOut()
{
document.getElementById("b1").src="b_pink.gif";
}
</script>
The function mouseOver() causes the image to shift to "b_blur.gif"
The function mouseOut() causes the image to shift to "b_pink.gif"
The Entire Code
<html>
<head>
<script type="text/javascript">
function mouseOver()
{
document.getElementById("b1").src="b_blue.gif";
}
function mouseOut()
{
document.getElementById("b1").src="b_pink.gif";
}
</script>
</head>
<body>
<a href="http://www.w3schools.com" target="_blank">
<img border="0" alt="visit w3schools!" src="b_pink.gif" id="b1" width="26" height="26" onmouseOver="mouseOver()" onmouseout="mouseOut()"/></a>
</body>
</html>
1 comment:
Great post. Thanks for sharing such useful coding in JavaScript and HTML for creating animated images.
http://www.cliffanimation.com
Post a Comment