JQuery - Sliding vertically aligned column

I have two columns, they both move to the left.

Inside the left column, I have a β€œtrigger” to hide the right column, this causes the left column to expand 100% when the right column is hidden. Right now I can return the right column, but the problem is that the right column is wrapped under the left column (of course, the left column is 100% wide) and not next to it, as if it were started at the beginning.

I'm not a jQuery / JavaScript programmer, but I think I'm in a good way with my jQuery code.

Here is my HTML:

<div id="wrapper">
  <div id="left-col">
  <div id="trigger"><a href="#">Toggle</a></div>
    <p>...</p>
  </div>
  <div id="right-col">Right Column</div>
  <br class="clear">
</div>

This is the jQuery that I have so far:

$(function() { 
  $("#left-col").addClass("wide80");
  $("#trigger a").click(function(){  
    $("#right-col").animate({width:'toggle'},350);
    $("#left-col").animate({width:'100%'},350); return false
   });
});

Any help you can give me would be greatly appreciated.

Thank.

+3
source share
2

- -

$(function() { 
    $("#left-col").addClass("wide80");
    $("#trigger a").click(function(){
        var leftCol = $("#left-col");

        if( leftCol.data('expanded') ) {
            leftCol.animate({width:'50%'},350);
            leftCol.data( 'expanded', false );
        } else {
            leftCol.animate({width:'100%'},350);
            leftCol.data( 'expanded', true );
        }

        $("#right-col").animate({width:'toggle'},350);

        return false;
    });
});
+2

, :

$(function() { 
  $("#left-col").addClass("wide");
  $("#trigger a").click(function(){
    var leftCol = $("#left-col");

    if( leftCol.data('expanded') ) {
        leftCol.animate({width:'60%'},350);
        leftCol.data( 'expanded', false );
        $("#right-col").toggle(350);
    } else {
        leftCol.animate({width:'100%'},350);
        leftCol.data( 'expanded', true );
        $("#right-col").hide();
    }
    return false;
  });
});
0

Source: https://habr.com/ru/post/1746485/


All Articles