最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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>

发布评论

评论列表(0)

  1. 暂无评论