I have a great piece of jQuery that swaps an image when the user hovers on an image. Check out the code below to see it.
It uses mouseenter
and mouseleave
.
I would like to modify it so that the image swap triggers when a specific input/label is :checked
.
You can see my demo page here:
http://test.davewhitley.com/not-wp/static_folder/index.php
To give you some background, I have 4 inputs/labels. When one is checked, a group of images will be swapped from black and white to their color version. I have two files for every image (image_s.jpg and image_o.jpg).
I am using the :checked
pseudo class to do some filtering. When an input is checked, some images remain full opacity
and other reduce to opacity:0.1
I want only the images that remain full opacity after checking the input to be color.
So basically I want to say in javascript:
Whenever an input is :checked
within #container
swap _s.jpg
with _o.jpg
.
Any help would be great.
UPDATE 1:
To clarify:
There is no image swap happening in the demo. The opacity
is just changed when an input is checked. In addition to the opacity change, I would like an image swap. All of the images would be black and white by default, and when an input is selected, the selected images would change from black and white to color (by using an image swap).
UPDATE 2: To put it simply, I would like all of the images to be black and white until the user clicks on one of the filter labels (print, web, typefaces, etc.) When a label is clicked, the non-filtered images will lower in opacity and the filtered images that remain full opacity will swap to a color image.
UPDATE 3: I can't seem to get the below answers to work for me. I am willing to abandon the input/:checked/pseudo-class filtering technique if it gets the job done. Also, I working test would help me a lot (JSfiddle).
Here is the image swap javascript:
$('.imgover').each(function() {
var std = $(this).attr("src");
var hover = std.replace("_s", "_o");
$(this).clone().insertAfter(this).attr('src', hover).removeClass('imgover').siblings().css({
position:'absolute'
});
$(this).mouseenter(function() {
$(this).stop().fadeTo(200, 0);
}).mouseleave(function() {
$(this).stop().fadeTo(200, 1);
});
});