This is less of a specific problem or error but more of a implementation question.
First of I\'d like to say that I\'ve been through a lot of fading image tutorials
You can get the src attribute of an image and use .replace() to replace the url on hover!
$('.fadein').each(function() {
var std = $(this).attr("src");
var hover = std.replace(".jpg", "_o.jpg");
$(this).clone().insertAfter(this).attr('src', hover).removeClass('fadein').siblings().css({
position:'absolute'
});
$(this).mouseenter(function() {
$(this).stop().fadeTo(600, 0);
}).mouseleave(function() {
$(this).stop().fadeTo(600, 1);
});
});
Or like:
$('.fadein').each(function() {
var std = $(this).attr("src");
var hover = std.replace(".jpg", "_o.jpg");
$(this).wrap('').clone().insertAfter(this).attr('src', hover).removeClass('fadein').siblings().css({
position:'absolute'
});
$(this).mouseenter(function() {
$(this).stop().fadeTo(600, 0);
}).mouseleave(function() {
$(this).stop().fadeTo(600, 1);
});
});
What the script does:
var std = $(this).attr("src"); grab the SRC attributevar hover = std.replace(".jpg", "_o.jpg"); $(this).wrap('')src and place it UNDERNEATH the first one .clone().insertAfter(this).attr('src', hover) .removeClass('fadein').siblings().css({position:'absolute'});