Created
May 20, 2013 18:53
-
-
Save internoma/5614412 to your computer and use it in GitHub Desktop.
JQuery imagen Hover
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
// RECORDAR QUE HAY QUE AÑADIR LA CLASE .over A LAS ETIQUETAS IMG | |
// LAS IMÁGENES QUE SE INTERCAMBIAN TIENEN LA CLAVE -ON | |
// EJEMPLO: <img class="over" src="archivo.png"> | |
$('img.over').each(function(){ | |
var t=$(this); | |
var src1= t.attr('src'); // inicial src | |
var newSrc = src1.substring(0, src1.lastIndexOf('.')); // obtiene el nombre sin extension | |
t.hover(function(){ | |
$(this).attr('src', newSrc + '-ON.' + /[^.]+$/.exec(src1)); // añade la clave de imagen | |
}, function(){ | |
$(this).attr('src', newSrc + '.' + /[^.]+$/.exec(src1)); // elimina la clave de imagen | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment