I am trying to get a slide left from right effect in jquery when I click a div. This is the HTML I am using.
<div id="myDiv" style="height: 70px; display: none; background-color:#eee; position: absolute; bottom: 1px; width: 100%">
<img style="margin-left: 9px; top: 8px; position: absolute" id="transparent-image" src="images/hover.png" alt="">
<p class="bi" style="display: inline; color: black; margin-left: 7%; position: absolute">Webbing in an alternative social network. based on intrests and interactions between people all over the world.</p>
And this is the jquery I am trying to use.
$(function()
{
$("#toggle").click(function () {
$(".sliding").css("display","none");
//$(".sliding").animate({left:'-240px'});
// Set the effect type
var effect = 'slide';
// Set the options for the effect type chosen
var options = { direction: 'left' };
// Set the duration (default: 400 milliseconds)
var duration = 10000;
$('#myDiv').toggle(effect, options, duration);
});
What I have achieved is the div is displaying onclick, but it is not sliding out in from left to right. Please help me out. I appreciate your help. Thanks.
I added the jsfiddle link as well. http://jsfiddle.net/yLyr599z/
I think this is what you want:
$(function() {
$("#toggle").click(function () {
$("#myDiv").animate({right:'0'});
});
});
#toggle{
position: absolute;
left: 10px;
bottom: 10px;
cursor: pointer;
}
#myDiv {
height: 70px;
background-color:#eee;
position: absolute;
bottom:0;
right: 100%;
width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="toggle">
Text to click. This will be an image though.
</div>
<div id="myDiv">
This text should slide out from left to right and overlap the onclick text.
</div>
A couple of key things:
right: 100%
on positioned elements.right: 0
since your width is 100%. That's the value you pass to the animate method in jQuery.