Hello.

There is a sidebar that appears and hides by a click. The problem is that in smartphones it does not hide. In smartphones it shows from the right and does not hide it. If you scroll to the right, the sidebar will be there.

Please help 3 days can not solve.

Also have a codepen

From the smartphone can be viewed by clicking on the link

$(document).ready(function() { const label = document.querySelector(".label"); const sidebar = document.querySelector(".sidebar"); const arrow = document.querySelector(".sidebar-arrow"); const mainContent = document.getElementById("main-content"); label.onclick = () => { if(window.innerWidth >= 992){ sidebar.classList.toggle("transform"); arrow.classList.toggle("rotate"); mainContent.classList.toggle("margin-left"); } else { sidebar.classList.toggle("transform"); arrow.classList.toggle("rotate"); } } }); 
 body { background-color: rgba(0, 0, 0, 0.5); overflow: hidden; } .sidebar { width: 350px; height: 100%; background: #000; top: 0; padding: 10px; position: absolute; transform: translateX(100%); right: 0px; transition: transform .2s linear; box-shadow: 3px 0 5px rgba(0, 0, 0, 0.5); } .sidebar .sidebar-content { height: 100%; overflow-y: scroll; } .sidebar .sidebar-content h4 { color: #fff; text-align: center; margin-top: 20px; font-family: 'Roboto', sans-serif; } .sidebar .sidebar-content table { width: 100%; color: #fff; text-align: center; font-family: 'Roboto', sans-serif; border-collapse: separate; border-spacing: 0 1em; border-radius: 5px; } .sidebar .sidebar-content table tr { background-color: #14161C; } .transform { transform: translateX(0); } .rotate { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sidebar.transform .label { background: transparent; transition: background 0.5s ease-in-out; } .label { width: 25px; height: 100%; background: #000; transition: background 0.5s ease-in-out; position: absolute; left: -25px; top: 0; box-shadow: 3px 0 5px rgba(0, 0, 0, 0.5); transition: opacity .2s linear; } .label .pointer { position: absolute; right: 0px; display: flex; top: 50vh; } .label .pointer span { color: #fff; -webkit-transform: rotate(-90deg); -ms-transform: rotate(-90deg); transform: rotate(-90deg); position: absolute; backface-visibility: hidden; right: 25px; top: 10px; font-family: 'Roboto', sans-serif; } .label .pointer .sidebar-arrow { background: url(http://mapfestival.az/assets/img/slider-arrow-left.png); background-size: 100%; background-position: 100%; position: relative; width: 25px; margin-right: 30px; height: 40px; cursor: pointer; color: #fff; transition: transform 0.5s ease-in-out; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="main-content"> <h1 class="main-title">asdasdas <br> QasdasdZ</h1> <button id="start-btn"><a href="javascript:void(0);">asdasdN</a></button> <div class="main-txt"> <p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.</p> </div> </div> <div id="sidebar" class="sidebar"> <div id="label" class="label"> <div class="pointer"> <div class="sidebar-arrow"></div> <span>LEADERBOARDS</span> </div> </div> <div class="sidebar-content"> <h4>LEADERBOARDS</h4> <table class="table"> <thead> <tr> <th scope="col">#</th> <th scope="col">First</th> <th scope="col">Last</th> <th scope="col">Handle</th> </tr> </thead> <tbody> <tr> <th scope="row">1</th> <td>Mark</td> <td>Otto</td> <td>@mdo</td> </tr> <tr> <th scope="row">2</th> <td>Jacob</td> <td>Thornton</td> <td>@fat</td> </tr> <tr> <th scope="row">3</th> <td>Larry</td> <td>the Bird</td> <td>@twitter</td> </tr> </tbody> </table> </div> </div> form, <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="main-content"> <h1 class="main-title">asdasdas <br> QasdasdZ</h1> <button id="start-btn"><a href="javascript:void(0);">asdasdN</a></button> <div class="main-txt"> <p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.</p> </div> </div> <div id="sidebar" class="sidebar"> <div id="label" class="label"> <div class="pointer"> <div class="sidebar-arrow"></div> <span>LEADERBOARDS</span> </div> </div> <div class="sidebar-content"> <h4>LEADERBOARDS</h4> <table class="table"> <thead> <tr> <th scope="col">#</th> <th scope="col">First</th> <th scope="col">Last</th> <th scope="col">Handle</th> </tr> </thead> <tbody> <tr> <th scope="row">1</th> <td>Mark</td> <td>Otto</td> <td>@mdo</td> </tr> <tr> <th scope="row">2</th> <td>Jacob</td> <td>Thornton</td> <td>@fat</td> </tr> <tr> <th scope="row">3</th> <td>Larry</td> <td>the Bird</td> <td>@twitter</td> </tr> </tbody> </table> </div> </div> 

  • a strange combination of js and jquery ..... use one thing, as jquery can do the same as js - Nikita Fast
  • @ NikitaFast yes indeed. Captain obvious - Demon __ ANT

1 answer 1

Yes, mobile phones have a problem with content that goes beyond the screen. You can use the "crutch": wrap the sidebar in a div, set it to width: 100% and overflow-x: hidden

  • did not work vseravno = ( - Demon __ ANT
  • Worked accept the answer thank you. And why is it a crutch? - Demon __ ANT
  • Well, because this is superfluous, in general, a div - it does not carry any meaning for the layout except for hiding the sidebar on mobile phones. I just don’t know of another option and I always do it myself :)) - humster_spb
  • Thanks :)) - Demon __ ANT