0

I would like to build a slidepanel with js. For that I would like a div that resizes when slider opens. Trying to do as following:

html

    <div class="wrapper">
       <div class="left">original content</div>
       <div class="right">sliding from right side</div>
    </div>

css

    .wrapper {width:100%;height:100%;position:relative;}
    .left {width:auto;height:100%;display:inline-block;}
    .right {width:50%;height:100%;}

This is the basic setup. I would like to have left take the full width. But when I click a button I want right to Slide in to 50%. Before adding js, I am trying to position the two divs, but it does not work. I tried with table cell, flex, ... I m just not able to get it right. Someone a good tip?

user3799112
  • 71
  • 12

1 Answers1

2

$("#expand").on("click", function(){
  $(".wrapper").toggleClass("expand");
});
.panel {
  height:100vh;
  transition: width .5s;
}
.left {
    float:left;
    width:100%;
    Background:red;
    Text-align:right;
  }
  .right {
    float:right;
    width:0%;
    background:#ddd;
    overflow:hidden;
  }
.pos {right:5px;}

.wrapper.expand .left {width:50%;}
.wrapper.expand .right {width:50%;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
  <div class="panel left">
    original content
    <button class="pos" id="expand">Click</button>
  </div>
  <div class="panel right">sliding from right side</div>
</div>
user3799112
  • 71
  • 12
Slonski
  • 824
  • 5
  • 12