Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery SlideOut Function from Right to Left

I am trying to slideout function from rightside in jQuery, by changing the code for "From Left to Right" but it's not functioning correctly... Can u please give me the right direction to modify...

http://jsfiddle.net/egUHv/

Presently I am using this code...

$(function() {
    $('#nav').stop().animate({'marginRight':'-100px'},1000);

    function toggleDivs() {
       var $inner = $("#nav");
       if ($inner.position().right == "-100px") {
           $inner.animate({right: 0});
           $(".nav-btn").html('<img src="images/slide-out.png" alt="open" />')
       }
       else {
           $inner.animate({right: "100px"}); 
           $(".nav-btn").html('<img src="images/slide-out.png" alt="close" />')
       }
    }
    $(".nav-btn").bind("click", function(){
        toggleDivs();
    });

});
like image 483
user1835490 Avatar asked Dec 03 '22 00:12

user1835490


2 Answers

just see this link it will be useful http://www.learningjquery.com/2009/02/slide-elements-in-different-directions

or use this

$("div").click(function () {
          $(this).show("slide", { direction: "left" }, 1000);
    });

Reference: http://docs.jquery.com/UI/Effects/Slide

like image 105
Kumar Avatar answered Dec 08 '22 01:12

Kumar


Try this : http://jsfiddle.net/egUHv/5/

$(function() {
$('#nav').stop().animate({'margin-right':'-100px'},1000);

function toggleDivs() {
var $inner = $("#nav");
if ($inner.css("margin-right") == "-100px") {
    $inner.animate({'margin-right': '0'});
    $(".nav-btn").html('<img src="images/slide-out.png" alt="open" />')
}
else {
    $inner.animate({'margin-right': "-100px"}); 
    $(".nav-btn").html('<img src="images/slide-out.png" alt="close" />')
}
}
$(".nav-btn").bind("click", function(){
    toggleDivs();
});

});
like image 38
Anujith Avatar answered Dec 08 '22 00:12

Anujith