I have found and customized this JQuery script, which displays different content when different links are pressed.
But, when the targetDiv is already visible, i would like the change effect to be fade, so it’s only slide effect when you open and close targetDiv.
Also, i can’t figure out why the content is visibly in about a half second on page load. Can i avoid that?
Here it is on JSFiddle: http://jsfiddle.net/XwN2L/179/
JQuery (newest version):
jQuery(function(){
jQuery('.targetDiv').hide();
jQuery('#close').click(function(){
jQuery('.targetDiv').slideUp();
});
jQuery('.showSingle').click(function(){
jQuery('.targetDiv').hide();
jQuery('#div'+$(this).attr('target')).slideDown();
});
});
HTML:
<div class="buttons">
<a class="showSingle" target="1">Div 1</a>
<a class="showSingle" target="2">Div 2</a>
<a class="showSingle" target="4">Div 4</a>
<a id="close">Close</a>
</div>
<br><br><br><br>
Lorem Ipsum<br>
<div id="div1" class="targetDiv">
<iframe width="420" height="315" src="http://www.youtube.com/embed/c1_LON8Ib2o" frameborder="0" allowfullscreen></iframe>
</div>
<div id="div2" class="targetDiv">
<iframe width="420" height="315" src="http://www.youtube.com/embed/s4GbpG-PypM" frameborder="0" allowfullscreen></iframe>
</div>
<div id="div4" class="targetDiv">
<iframe width="560" height="315" src="http://www.youtube.com/embed/DHef3iAjxiM" frameborder="0" allowfullscreen></iframe>
</div>
Lorem Ipsum
Working Demo http://jsfiddle.net/efgFL/2/
Use
is(':visible')link: http://api.jquery.com/visible-selector/For the second part the
blahtext is not in any container where the show/hide is happening thats why.Hope this helps,
code