2

Is there an easy way to make this into a sliding div that goes from left to right basing what code snippet I have provided below that is up/down?

So rather having it go up/down, make it go left/right?

$(document).ready(function() {

    $("#open").click(function(){
        $("div#panel").slideDown("slow");

    }); 

    $("#close").click(function(){
        $("div#panel").slideUp("slow"); 
    });     

    $("#toggle a").click(function () {
        $("#toggle a").toggle();
    });

});
Marcel Gwerder
  • 8,353
  • 5
  • 35
  • 60
Hybrid82
  • 253
  • 1
  • 2
  • 14

3 Answers3

2

You can use the animation on hide to slide it from left/right.

$(document).ready(function() {

    $("#open").click(function(){
        $("div#panel").show('slide', {direction: 'right'}, "slow");
    }); 

    $("#close").click(function(){
        $("div#panel").hide('slide', {direction: 'left'}, "slow");
    });     

    $("#toggle a").click(function () {
        $("#toggle a").toggle();
    });

});
Ashis Kumar
  • 6,494
  • 2
  • 21
  • 36
1

You can use jQueryUI and the slide effect.

Example:

$("div#panel").hide("slide", {direction: "left" }, 1000);
$("div#panel").show("slide", { direction: "right" }, 1000);
geekchic
  • 2,371
  • 4
  • 29
  • 41
  • If the above answer does not work, I'll give this a try. Would I need the jqueryUI to be able to implement this code? – Hybrid82 Aug 11 '13 at 12:22
  • You would need to include jqueryUI. – geekchic Aug 11 '13 at 12:24
  • Alrighty, I at the moment do not need jqueryUI for my project, but I'm sure I would down the road - when that times comes, I'll use what you posted as a reference so Thank you for helping out ;) – Hybrid82 Aug 11 '13 at 12:29
1

You can use jQuery animate http://api.jquery.com/animate/

$(document).ready(function() {

    var  myDivWidth = $( "div#panel" ).width();

    $("#open").click(function(){
        $( "div#panel" ).css({'width' : '0' }).animate({width: myDivWidth}, 'slow');
    }); 

    $("#close").click(function(){
        $( "div#panel" ).animate({width: 0}, 'slow'); 
    });      

});

Update :

Here is the jsfiddle http://jsfiddle.net/ck4PX/
Updated jsfiddle http://jsfiddle.net/QGXQm/

Fouad Fodail
  • 2,653
  • 1
  • 16
  • 16