tags:

views:

501

answers:

1

The markup below is used for my jQuery carousel widget. The first div serves as a preview div for the currently selected template thumbnail. When a user mouseover event occurs inside the carousel on any thumbnail image, I'd like the preview image to update to show the full size thumbnail of that image (and then revert back to the default onmouseout).

The carousel images and the preview image are the same size, I'm just setting the size of the carousel images via css to appear smaller.

//this is my full size preview image
<div class="selectedImage">
    <img src="../wp-content/themes/mytheme/screenshot.jpg" />
</div>
// this is the element that moves the carousel images
<a href="#"><img class="prev" src="../wp-content/themes/mytheme/more.jpg" /></a>

//This is the carousel. I'd like hover events to update the preview image
// with the mouseover image, but revert back to the default onmouseout.
<div class="carousel">
    <ul>
        <li><img src="../wp-content/themes/mytheme/screenshot1.jpg" class="selected" /></li>
        <li><img src="../wp-content/themes/mytheme/screenshot2.jpg" class="selected" /></li>
        <li><img src="../wp-content/themes/mytheme/screenshot3.jpg" class="selected" /></li>        
    </ul>
</div>

btw, I'm using the jcarousellite_1.0.1.min.js plugin for the carousel.

+1  A: 

DEMO: http://jsbin.com/uyupu

$(function() {
    $(".carousel").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev"
    });

  $('.carousel ul li').hover(function(e) {

  var img_src = $(this).children('img').attr('src');
  $('.selectedImage img').fadeOut(200).attr('src',img_src).fadeIn(200);  

}
,function() {

//do here what you want, or simply hide image!
$('.selectedImage img').fadeOut(200);
   });

});
aSeptik
Sweeeeet! When I run it as is, it changes the preview image perfectly, but onmouseout the preview image disappears along with the default image. How can I make the default image come back onmouseout?
Scott B
you mean that you have a first predefined image that you want come back OR you just want display the latest hovered image!?
aSeptik
The former. I've figured it out. jQuery is pretty sweet. Thanks for setting me on the path :)
Scott B
no problem bro! ;-)
aSeptik