You may use jQuery UI to do the job.
(I write this additional answer in order to show the effects of both slide-in from left toggle and slide-in from right toggle with the contents properly positioned
and I believe it can help someone who is in need of such a common and normal requirement)
The trick is to set the direction ("left" or "right") and use the "slide" effect.
function slideleft(){
var effect = 'slide';
var options = { direction: "left" };
var duration = 300;
$('#myDiv1').toggle(effect, options, duration);
}
function slideRight(){
var effect = 'slide';
var options = { direction: "right" };
var duration = 300;
$('#myDiv2').toggle(effect, options, duration);
}
So a fully working script (with contents box properly positioned for the two slide-toggle effects) is as follows:
or see this DEMO
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script
src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"
integrity="sha256-xLD7nhI62fcsEZK2/v8LsBcb4lG7dgULkuXoXB/j91c="
crossorigin="anonymous"></script>
<style>
#button1 {
position:absolute;
left:0px;
top:50px;
}
#button2 {
position:absolute;
right:0px;
top:50px;
}
#myDiv1 {
position:absolute;
left:0px;
top:150px;
width:300px;
padding:10px;
background-color:#FFFFFF;
border:1px solid #333;
display:none;
}
#myDiv2 {
position:absolute;
right:0px;
top:150px;
width:300px;
padding:10px;
background-color:#FFFFFF;
border:1px solid #333;
display:none;
}
</style>
<h2>Slide toggle (Left to Right) and (Right to Left)</h2>
<p>
<button id="button1" onclick="javascript:slideleft();">Slide Toggle (from left)</button>
<button id="button2" onclick="javascript:slideRight();">Slide Toggle (from right)</button>
</p>
<div id="myDiv1">
<p>LEFT BOX - 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 id="myDiv2">
<p>RIGHT BOX - 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>
<script>
function slideleft(){
var effect = 'slide';
var options = { direction: "left" };
var duration = 300;
$('#myDiv1').toggle(effect, options, duration);
}
function slideRight(){
var effect = 'slide';
var options = { direction: "right" };
var duration = 300;
$('#myDiv2').toggle(effect, options, duration);
}
</script>