I would advise to use jQuery library for a very simple solution. Something like that:
<html>
<head>
<title>...</title>
<script type="text/javascript" src="scripts/jquery-1.7.1.min.js"></script>
</head>
<body>
<img alt="Image" id="image" />
<script type="text/javascript">
$(document).ready(function() {
imageElement = $("#image");
imageElement.attr("src", "small.png");
imageElement.hover(
function() {
$(this).attr("src", "big.png");
},
function() {
$(this).attr("src", "small.png");
}
);
});
</script>
</body>
</html>
In this code sample, I assume you use a big version of the image, "big.png", and a small one, created by re-sampling a big one down, "small.png". At first, your element
img
does not show any image. When the document is loaded and its DOM is ready, a small one is installed and then the images are swapped on the events of hovering into and out of the image.
I did not use the click event, as you did not explain on what event should you make the image small again. If you want to use the event
onclick
, use the jQuery event
click
, with only one method argument (handler). Please see:
http://api.jquery.com/click/[
^].
For understanding of the rest of this code, please see:
http://api.jquery.com/attr/[
^],
http://api.jquery.com/category/selectors/[
^],
http://api.jquery.com/category/events/[
^],
http://api.jquery.com/ready/[
^].
For more information on jQuery, please see:
http://en.wikipedia.org/wiki/JQuery[
^],
http://docs.jquery.com/Main_Page[
^].
—SA