Slide toggle from right-to-left and left-to-right.
This is the version #1 of the DEMO
by Ahmad Sharif
HTML
<div id="body">
<h2>Slide toggle from right to left.</h2>
<hr/>
<p>
<button id="button" class="myButton">Run Effect</button>
</p>
<div id="myDiv">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
<div class="other_details">This should move parallely with resize of div being toggled.</div>
</div>
CSS
* {
margin: 0px !important;
overflow: hidden !important;
}
#myDiv {
background-color:#eee;
float:right;
width:200px;
}
.other_details{
float:right;
font-weight:bold;
width:200px;
}
JavaScript
$(".myButton").click(function () {
var effect = 'width';
var duration = 500;
//if the current width is 200px, then the target width is 0px otherwise the target width is 200px
var targetWidth = $('#myDiv').css("width")=="200px"?"0px":"200px";
//Check if the div was hidden then display it
if(!$("#myDiv").is(":visible")){
$("#myDiv").show();
}
$('#myDiv').animate({width: targetWidth},duration,function(){
if($(this).css("width")=="0px"){
$(this).hide();
}
else{
$(this).show();
}
});
});