javascript - Sidebar toggled that slide to the right - Stack Overflow

below is my code:HTML<div id="wrapper" style="background-color:red"><div i

below is my code:

HTML

<div id="wrapper" style="background-color:red">
    <div id="sidebar-wrapper" style="background-color:yellow">sidebar
        <div id="result"></div>
    </div>
     <div id="header" class="container-fluid">
        <div class="navbar">
            <a href="#menu-toggle" id="menu-toggle" >Press</a>    
            <div>This is a serious health setback for me personally, but one of CN's core strengths is that we have a very experienced and tightly-knit senior  <span id="counterId"></span></div>
        </div>
    </div>
  </div>

CSS

#wrapper {
    padding-left: 0;
    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transition: all 0.5s ease;
}
#wrapper.toggled {
    padding-left: 250px;
}
#sidebar-wrapper {
    z-index: 1000;
    position: fixed; 
    left: 250px;
    width: 0;
    height: 100%;
    margin-left: -250px;
    overflow-y:auto;
    background: #050545;
    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transition: all 0.5s ease;
    box-shadow: inset -10px 0px 10px -7px grey;
}
#wrapper.toggled #sidebar-wrapper {
    width: 250px;
}

JS

$("#menu-toggle").click(function(e) {
    e.preventDefault();
    $("#wrapper").toggleClass("toggled");
});

The jsfiddle is below:

JSFIDDLE

As you guys can see, it is a sidebar slide to the right when I press the link. It kinda squeeze the content on the right side of the screen when I press it.

What I want is the the right side of the content to slide to the right to go behind the screen, not squeeze all content together. Any ideas?

below is my code:

HTML

<div id="wrapper" style="background-color:red">
    <div id="sidebar-wrapper" style="background-color:yellow">sidebar
        <div id="result"></div>
    </div>
     <div id="header" class="container-fluid">
        <div class="navbar">
            <a href="#menu-toggle" id="menu-toggle" >Press</a>    
            <div>This is a serious health setback for me personally, but one of CN's core strengths is that we have a very experienced and tightly-knit senior  <span id="counterId"></span></div>
        </div>
    </div>
  </div>

CSS

#wrapper {
    padding-left: 0;
    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transition: all 0.5s ease;
}
#wrapper.toggled {
    padding-left: 250px;
}
#sidebar-wrapper {
    z-index: 1000;
    position: fixed; 
    left: 250px;
    width: 0;
    height: 100%;
    margin-left: -250px;
    overflow-y:auto;
    background: #050545;
    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transition: all 0.5s ease;
    box-shadow: inset -10px 0px 10px -7px grey;
}
#wrapper.toggled #sidebar-wrapper {
    width: 250px;
}

JS

$("#menu-toggle").click(function(e) {
    e.preventDefault();
    $("#wrapper").toggleClass("toggled");
});

The jsfiddle is below:

JSFIDDLE

As you guys can see, it is a sidebar slide to the right when I press the link. It kinda squeeze the content on the right side of the screen when I press it.

What I want is the the right side of the content to slide to the right to go behind the screen, not squeeze all content together. Any ideas?

Share Improve this question edited Aug 17, 2015 at 7:37 Shehary 9,99010 gold badges46 silver badges75 bronze badges asked Aug 17, 2015 at 7:32 CoolguyCoolguy 2,28512 gold badges56 silver badges81 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Give fixed width as the width of the viewport to the #wrapper element.

Use vw to set the width.

1/100th of the width of the viewport.

#wrapper {
  ...
  width: 100vw; // vw: Viewport width when page is loaded
}

More about vw

Demo

$("#menu-toggle").click(function(e) {
  e.preventDefault();
  $("#wrapper").toggleClass("toggled");
});
* {
  margin: 0;
  padding: 0;
}
#wrapper {
  width: 100vw;
  padding-left: 0;
  -webkit-transition: all 0.5s ease;
  -moz-transition: all 0.5s ease;
  -o-transition: all 0.5s ease;
  transition: all 0.5s ease;
}
#wrapper.toggled {
  padding-left: 250px;
}
#sidebar-wrapper {
  z-index: 1000;
  position: fixed;
  left: 250px;
  width: 0;
  height: 100%;
  margin-left: -250px;
  overflow-y: auto;
  background: #050545;
  -webkit-transition: all 0.5s ease;
  -moz-transition: all 0.5s ease;
  -o-transition: all 0.5s ease;
  transition: all 0.5s ease;
  box-shadow: inset -10px 0px 10px -7px grey;
}
#wrapper.toggled #sidebar-wrapper {
  width: 250px;
}
<script src="https://ajax.googleapis./ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<div id="wrapper" style="background-color:red">
  <div id="sidebar-wrapper" style="background-color:yellow">sidebar
    <div id="result"></div>
  </div>
  <div id="header" class="container-fluid">
    <div class="navbar"> <a href="#menu-toggle" id="menu-toggle">Press</a> 
      <div>This is a serious health setback for me personally, but one of CN's core strengths is that we have a very experienced and tightly-knit senior <span id="counterId"></span>

      </div>
    </div>
  </div>
</div>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745091868a4610739.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信