0

With reference of Mr.Vytautas Butkus, I have used his code, Using his code I can get vertical effect but I want horizontal effect of show and hide.

$(document).ready(function(){
      var $content = $(".content").hide();
      $(".toggle").on("click", function(e){
        $(this).toggleClass("expanded");
        $content.slideToggle();
      });
    })

So please Suggest me what can I do for Horizontal hide and show effect of div?

AloNE
  • 311
  • 3
  • 7
  • 15

4 Answers4

2

slideToggle does slideUp and down. So use .animate() instead of .slideToggle()

You can use

$('selector').animate({width: 'toggle'});

Your code:

   $(document).ready(function(){
          var $content = $(".content").hide();
          $(".toggle").on("click", function(e){
            $(this).toggleClass("expanded");
            $content.animate({width: 'toggle'});
          });
        })
Praveen
  • 55,303
  • 33
  • 133
  • 164
1

Use .toggle( "slide" ) like this:

      var $content = $(".content").hide();
      $(".toggle").on("click", function(e){
        $(this).toggleClass("expanded");
         $content.toggle( "slide" );
      });

Here is the demo

Rajeev Bera
  • 2,021
  • 1
  • 16
  • 30
Nishu Tayal
  • 20,106
  • 8
  • 49
  • 101
0

You can do this by expanding width. If you don't want to use jQuery.animate function then you can also do this by using CSS3 transition property.

Jay Shukla
  • 5,794
  • 8
  • 33
  • 63
0

I agree with user1671639's response.

But, for a smoothest animation on iPad, you can also use the excellent Transit to create the animation in CSS3 simply.

And add a fall back on normal JavaScript animation for old browsers including IE9.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Jaycreation
  • 2,029
  • 1
  • 15
  • 30