I am working on a band blurb page, example here.
The idea is to click on a photo which will display the band member blurb on the left, overlaying the overall band description.
My issue with the current code is that using toggle to display the alternative individual blurbs means that when you click between the different members, sometimes the toggle state resets and it seems like nothing is happening. Each time you click a photo, that persons bio should display. Only when you click the same one twice, or a 'return to band bio' button (not yet on the page) should the main bio display.
My current code is below:
jQuery(document).ready(function($) {
$('#gotoben').toggle(function() {
$('li.gotoben').fadeTo("slow", 1);
$("#dan").hide();
$("#ben").show();
$('li.gotoben').siblings().fadeTo("slow", 0.3);
},
function () {
$('li.gotoben').fadeTo("slow", 1);
$('li.gotoben').siblings().fadeTo("slow", 1);
$("#ben, #dan").hide();
});
$('#gotodan').toggle(function() {
$('li.gotodan').fadeTo("slow", 1);
$("#ben").hide();
$("#dan").show();
$('li.gotodan').siblings().fadeTo("slow", 0.3);
},
function () {
$('li.gotodan').fadeTo("slow", 1);
$('li.gotodan').siblings().fadeTo("slow", 1);
$("#dan, #ben").hide();
});
});
I have tried using the .click function but also cannot make everything work 100% smoothly.
Can anyone help me make this work?
EDIT - WORKING CODE
The only thing added here to patricks code is the inclusion of the jQuery stop
function.
jQuery(document).ready(function($) {
$('.bigLeft div:gt(0)').hide();
$('ol.band li').click(function() {
var $th = $(this);
// Hide the current profiles
$(".bigLeft").children().hide();
if( $th.hasClass('selected') ) {
$th.stop(true, false).siblings().fadeTo("slow", 1);
$th.removeClass('selected');
$('#theBand').show(); // <-- change the ID to the default
} else {
$th.addClass('selected');
// Grab the ID of the one that was clicked
var id = $th.attr('id');
// Fade in the current, and fade the siblings
$th.stop(true, false).fadeTo("slow", 1)
.siblings().removeClass('selected').stop(true, false).fadeTo("slow", 0.3);
// Show the clicked profile by concatenating the ID clicked with '_profile'
$("#" + id + "_profile").show();
}
});
});