Skip to content

Instantly share code, notes, and snippets.

@internoma
Created May 20, 2013 18:53
Show Gist options
  • Save internoma/5614412 to your computer and use it in GitHub Desktop.
Save internoma/5614412 to your computer and use it in GitHub Desktop.
JQuery imagen Hover
// 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