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 and I have a basic understanding of the different kinds. I hope this doesn’t get thrown out along with the other hundreds of questions about fading images.
This is basically what I would like: An image fading into another image on hover using javascript and preferably jQuery. I would create two images—one named image.jpg and another named image_o.jpg. They would reside in the same folder.
Here’s what the html markup would look like:
<img class="imghover" src="image.jpg" />
The javascript would require me to have the imghover class on all the images that I want to hover. The script would detect the second image named imghover_o.jpg and use it for the second image in the hover fade transition.
There would be no required CSS or background-image for the transition.
I will have several of these images in a grid and they will all need to have the fade transition. So, you can see that I do not want to make a new CSS class for every image, or have extra script and html markup that will get cumbersome.
All of the above is achieved with this Daniel Nolan script minus the fade transition. The script just swaps the image with no fade, but it is set up perfectly with minimal code.
So you could say that I just want add a fade transition to the Daniel Nolan rollover script. Is is possible to remake his script using jQuery?
Is this possible (with jQuery)?
You can get the
srcattribute of an image and use.replace()to replace the url on hover!WORKING DEMO
Or like:
THIS
What the script does:
var std = $(this).attr("src");grab the SRC attributevar hover = std.replace(".jpg", "_o.jpg");$(this).wrap('<div />')srcand place it UNDERNEATH the first one.clone().insertAfter(this).attr('src', hover).removeClass('fadein').siblings().css({position:'absolute'});