toggle - jQuery Panels - Weird Content Effect -
i getting weird jquery effect on website building.
http://www.real-visual.com/site/technology/
on page, in left panel, see 4 orange links. if click one, slides open content panel. then, if click different orange link, slides closed first panel , slides open second one.
however, notice weird effect where, when slide sliding closed, content inside changes.
here example of jquery code powers these slides:
$("#panel-2-button").click(function() { if ($('.togglepanel').is(':visible')) { $(".togglepanel").hide("slide", { direction: "left" }, 1000); } $("#content-inner-panel-2").toggle("slide", { direction: "left" }, 1000); }); $("#panel-2-button-medium").click(function() { if ($('.togglepanel').is(':visible')) { $(".togglepanel").hide("slide", { direction: "left" }, 1000); } $("#content-inner-panel-2-medium").toggle("slide", { direction: "left" }, 1000); }); $("#panel-2-button-large").click(function() { if ($('.togglepanel').is(':visible')) { $(".togglepanel").hide("slide", { direction: "left" }, 1000); } $("#content-inner-panel-2-large").toggle("slide", { direction: "left" }, 1000); });
and here example of html:
<div id="content-inner-panel-2-medium" class="togglepanel"> <h1>microsoft kinect</h1> <p>text here</p> <div id="panel-2-close-medium"></div> </div> <div id="content-inner-panel-3-medium" class="togglepanel"> <h1>large screen & immersive</h1> <p>text here</p> <div id="panel-3-close-medium"></div> </div> <div id="content-inner-panel-4-medium" class="togglepanel"> <h1>mobile phones & tablets</h1> <p>text here</p> <div id="panel-4-close-medium"></div> </div> <div id="content-inner-panel-5-medium" class="togglepanel"> <h1>games controllers & remotes</h1> <p>text here</p> <div id="panel-5-close-medium"></div> </div>
does know why weird content-switcharound bug occuring when slide closes , how fix it?
the problem line:
if ($('.togglepanel').is(':visible')) { $(".togglepanel").hide("slide", { direction: "left" }, 1000); }
specifically:
$(".togglepanel").hide("slide", { direction: "left" }, 1000);
that line hides first element in .togglepanel finds (which kinect one) , hides that. need find id of visible .togglepanel , hide id, not class:
var visiblepanel = 'none'; $('.togglepanel').each(function(){ if ($(this).is(':visible')) { visiblepanel = $(this).attr('id'); } }); if (visiblepanel != 'none'){ $(visiblepanel).hide("slide", { direction: "left" }, 1000); }
that last line might need prepend # symbol so:
if (visiblepanel != 'none'){ $('#' + visiblepanel).hide("slide", { direction: "left" }, 1000); }
Comments
Post a Comment