- Image Rollovers by <img> and <a> events
- <a href="http://www.google.com" >
- <img alt="arrow" name="ArrowImage"
- onmouseover="document.ArrowImage.src='Images/arrow_on.gif'"
- onmouseout="document.ArrowImage.src='Images/arrow_off.gif'"
- src="Images/arrow_off.gif" />
- </a>
- <a href="http://www.google.com"
- onmouseover="document.arrow.src='images/arrow_on.gif'"
- onmouseout="document.arrow.src='images/arrow_off.gif'">
- <img src="images/arrow_off.gif" width="147" height="82"
- name="arrow" alt="arrow" />
- </a>
- <a href="http://www.google.com" >
- This is some text explaining the image. If you mouse over it, the rollover won't change.
- <img alt="arrow" name="ArrowImage"
- onmouseover="document.ArrowImage.src='Images/arrow_on.gif'"
- onmouseout="document.ArrowImage.src='Images/arrow_off.gif'"
- src="Images/arrow_off.gif" />
- </a>
- <a href="http://www.google.com"
- onmouseover="document.arrow.src='images/arrow_on.gif'"
- onmouseout="document.arrow.src='images/arrow_off.gif'">
- This is some text explaining the image. If you mouse over it, the rollover WILL change.
- <img src="images/arrow_off.gif" width="147" height="82"
- name="arrow" alt="arrow" />
- </a>
- // defined in application.js for example:
- $("img").hover(function onmouseover(){
- $(this).attr("src", "Images/arrow_on.gif");
- }, function onomouseout(){
- $(this).attr("src", "Images/arrow_off.gif");
- });
- /* use a more specific selector in your actual code */
- a {
- /* on state */
- background: url(Images/arrow.gif) no-repeat 0 0;
- }
- a:hover {
- /* default state */
- background: url(Images/arrow.gif) no-repeat -50px 0;
- }
- a#rollover {
- background: url("normal.jpg") no-repeat 0 0;
- }
- a#rollover:hover {
- background: url("rollover.jpg") no-repeat 0 0;
- }
- <a id="rollover" href="link.html"><img id="rolloverimage" src="image.jpg" width="100" height="100" alt="text"/></a>
- var atag = document.getElementById('rollover');
- atag.onmouseover = function() {
- document.getElementById('rolloverimage').src = 'rollover.jpg';
- }
- atag.onmouseout = function() {
- document.getElementById('rolloverimage').src = 'image.jpg';
- }