The htmL Code
The htmL Code
The HTML code looks like this:
<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>
Note that 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 be executed. This function inserts the
original image again.
the JavaScript Code
The changing between the images is done with the following JavaScript:
<script type="text/javascript">
function mouseOver()
{
document.getElementById("b1").src ="b_blue.gif";
}
function mouseOut()
{
document.getElementById("b1").src ="b_pink.gif";
}
</script>
The function mouseOver() causes the image to shift to “b_blue.gif.”
The function mouseOut() causes the image to shift to “b_pink.gif.”
the entire Code
In the following example, we combine the HTML and JavaScript code to produce
animation.
The resulting animation is shown in Figure 24.1.
You can try this example on the www.w3schools.com Web site or include
you own graphic files in the directory with your html source, substituting
for b_blue and b_pink in the html source code.
Try it yourself >>
<html>
<head>
<script type="text/javascript">
function mouseOver()
{
document.getElementById("b1").src ="b_blue.gif";
}
function mouseOut()
{
document.getElementById("b1").src ="b_pink.gif";
}
(continued)
Learn JavaScript and ajax with w3schools
140
</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 HTML code looks like this:
<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>
Note that 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 be executed. This function inserts the
original image again.
the JavaScript Code
The changing between the images is done with the following JavaScript:
<script type="text/javascript">
function mouseOver()
{
document.getElementById("b1").src ="b_blue.gif";
}
function mouseOut()
{
document.getElementById("b1").src ="b_pink.gif";
}
</script>
The function mouseOver() causes the image to shift to “b_blue.gif.”
The function mouseOut() causes the image to shift to “b_pink.gif.”
the entire Code
In the following example, we combine the HTML and JavaScript code to produce
animation.
The resulting animation is shown in Figure 24.1.
You can try this example on the www.w3schools.com Web site or include
you own graphic files in the directory with your html source, substituting
for b_blue and b_pink in the html source code.
Try it yourself >>
<html>
<head>
<script type="text/javascript">
function mouseOver()
{
document.getElementById("b1").src ="b_blue.gif";
}
function mouseOut()
{
document.getElementById("b1").src ="b_pink.gif";
}
(continued)
Learn JavaScript and ajax with w3schools
140
</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>
0 comments:
Post a Comment