Very simple jQuery rollover
Posted
by Gusepo
on Stack Overflow
See other posts from Stack Overflow
or by Gusepo
Published on 2010-03-12T14:11:42Z
Indexed on
2010/03/13
13:25 UTC
Read the original article
Hit count: 382
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 img
s 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 img
s 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);
}
);
}
© Stack Overflow or respective owner