How to push an element outside the screen without the browser just expanding the viewport?

前端 未结 3 1191
暖寄归人
暖寄归人 2020-12-24 14:37

Some times it\'s nice to be able to slide things out of the viewport to hide them, for example when making hide-able sidebars or panels. But when I push something past the r

3条回答
  •  执念已碎
    2020-12-24 15:29

    A simple solution (admittedly not always viable) would be to set position:fixed on the sidebar instead of position:absolute.

    FIDDLE

    $('.sidebar').on('click', function() {
      $(this).css('right', -250);
    });
    .sidebar {
      position: fixed;
      top: 0px;
      right: 0px;
      bottom: 0px;
      width: 250px;
      -webkit-transition: right 0.2s ease-out;
      -moz-transition: right 0.2s ease-out;
      transition: right 0.2s ease-out;
      cursor: pointer;
      background-color: cornflowerblue;
    }
    
    

提交回复
热议问题