jQuery carousel clicks update <select> list's "selected" option to match clicked item's title attrib
Posted
by Scott B
on Stack Overflow
See other posts from Stack Overflow
or by Scott B
Published on 2010-03-17T01:57:21Z
Indexed on
2010/03/17
2:01 UTC
Read the original article
Hit count: 264
jQuery
The code below allows me to change a preview image outside the carousel widget so that it matches the element under the mouse. For example, if the user mouses over image2's thumbnail, the script updates .selectedImage so that it displays image2's full size version.
I'd like to enhance it so that the #myThumbs options listing updates its "selected" option to match the carousel image that receives a click.
Mouseover changes the preview image and click changes the select list to match the same name.
The items in the carousel will have the same title attribute as the items in the select list, so I would expect that I can pass that value from the carousel to the select list.
$(function() {
$("#carousel").jCarouselLite({
btnNext: ".next",
btnPrev: ".prev",
visible: 6,
mouseWheel: true,
speed: 700
});
$('#carousel').show();
$('#carousel ul li').hover(function(e) {
var img_src = $(this).children('img').attr('src');
$('.selectedImage img').attr('src',img_src);
}
,function() {
$('.selectedImage img').attr('src', '<?php echo $selectedThumb; ?>');});
});
<select id="myThumbs">
<option>image1</option>
<option selected="selected">image2</option>
<option>image3</option>
</select>
© Stack Overflow or respective owner