Created
August 2, 2011 22:10
-
-
Save sakunyo/1121362 to your computer and use it in GitHub Desktop.
js image over
This file contains hidden or 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
(function(){ | |
var suffix = { normal : '_no.', over : '_on.'} | |
$('a.over, img.over, input.over').each(function(){ | |
var a, | |
img, | |
el = $(this).get(0), | |
el_name = el.nodeName.toLowerCase(); | |
src_no, | |
src_on, | |
cache; | |
if( el_name === 'a' ){ | |
a = $(this); | |
img = $('img',this); | |
}else if( el_name === 'img' || el_name === 'input' ){ | |
img = $(this); | |
} | |
src_no = img.attr('src'); | |
src_on = src_no.replace(suffix.normal, suffix.over); | |
if( el_name === 'a' ){ | |
a.bind("mouseover focus",function(){ img.attr('src',src_on); }) | |
.bind("mouseout blur", function(){ img.attr('src',src_no); }); | |
}else if( el_name === 'img' ){ | |
img.bind("mouseover",function(){ img.attr('src',src_on); }) | |
.bind("mouseout", function(){ img.attr('src',src_no); }); | |
}else if( el_name === 'input' ){ | |
img.bind("mouseover focus",function(){ img.attr('src',src_on); }) | |
.bind("mouseout blur", function(){ img.attr('src',src_no); }); | |
} | |
// cache img | |
cache = document.createElement('img'); | |
cache.src = src_on; | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment