I'm just starting out with jQuery in a Drupal environment.
I have several thumbnails, and I want that when you click one of them a large picture appears in the viewport (a hidden div appears). There may be better ways to accomplish what I do, but I need to do it this way.
This is what I have:
$(document).ready(function() {
$('#bigpic2').hide();
$('#bigpic3').hide();
$('a#thumb1').click(function() {
$('#bigpic2').hide(); $('#bigpic3').hide();
$('#bigpic3').toggle(200);
return false;
});
$('a#thumb2').click(function() {
$('#bigpic1').hide(); $('#bigpic3').hide();
$('#bigpic2').toggle(200);
return false;
});
$('a#thumb3').click(function() {
$('#bigpic1').hide(); $('#bigpic2').hide();
$('#bigpic3').toggle(200);
return false;
});
});
Besides some ugly code, it doesn't work properly. The first large photo does not appear when the page does, and clicking on more thumbnails shows the right div, but never hides (only one large photo should be visible at a time in the "viewport").
My HTML looks like
<table><tr>
<td><a href="#" mce_href="#" id="thumb1">...thumb1...</td>
<td><a href="#" mce_href="#" id="thumb2">...thumb2...</td>
<td><a href="#" mce_href="#" id="thumb3">...thumb3...</td>
</tr>
<tr><td colspan="3">
<div id="bigpic1">... </div>
<div id="bigpic2">...</div>
<div id="bigpic3">...</div>
</td></tr></table>
source
share