-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Rollover effect, changes element's src attribute on hover, e.g.: | ||
* | ||
* image.png?foo=bar => image_h.png?foo=bar | ||
* | ||
* Pass true to preload images. | ||
*/ | ||
jQuery.fn.rollover = function(preload) { | ||
this.filter(':not([src*="_h."])').each(function() { | ||
var a = this.src, b = this.src.replace(/\.(\w+(\?[^$]*)?)$/, '_h.$1'); | ||
$(this).hover(function() { this.src = b; }, function() { this.src = a; }); | ||
if (preload) { | ||
var i = new Image; | ||
i.src = b; | ||
} | ||
}); | ||
return this; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
|
||
<html> | ||
<head> | ||
<title>jQuery Image Rollover</title> | ||
<script type='text/javascript' src='javascripts/jquery-1.2.6.min.js'></script> | ||
<script type='text/javascript' src='javascripts/jquery.rollover.js'></script> | ||
<link rel="stylesheet" href="stylesheets/main.css" type="text/css" /> | ||
</head> | ||
<body> | ||
<div id='container'> | ||
|
||
<p>Images from <a href='http://www.externalharddrive.com/graphics/bullets/index.html'>External Hard Drive</a></p> | ||
|
||
<img src='images/r.gif' /> | ||
<img src='images/r.gif?foo=bar' /> | ||
<img src='images/r_h.gif' /> | ||
|
||
<script type='text/javascript'> | ||
$(function() { | ||
$('img').rollover(); | ||
}); | ||
</script> | ||
|
||
</div> | ||
</body> | ||
</html> |