Very simple jQuery rollover
- by Gusepo
I made a very simple jQuery img rollover function inspired by this one:
http://www.smileycat.com/miaow/archives/000224.php.
It just check all the imgs that contain _off in their name and swap them with an img with the same name but "_on" instead of "_off".
Since I can't use background imgs in my layout, I feel that's an handy solution.
But I've got the feeling that the swapping is not smooth, like if the function runs slow.
What do you think?
Are there ways to optimize it?
Here is the code:
function roll_over() {
$("img[src*='_off']").hover(
function() {
var stringa = $(this).attr("src");
var stringa = stringa.replace("_off", "_on");
$(this).attr("src", stringa);
},
function() {
var stringa = $(this).attr("src");
var stringa = stringa.replace("_on", "_off");
$(this).attr("src", stringa);
}
);
}