简体   繁体   English

在页面第一部分时如何隐藏元素

[英]How to hide element when it on first section of page

I have a one-page website with 4 sections, and it's not scrollable. 我有一个包含4个部分的单页网站,它不能滚动。 I have burger menu button for moving between sections, it has fixed position so it shows on all sections but I don't need it on the first section. 我有汉堡菜单按钮,可以在各个部分之间移动,它具有固定的位置,因此可以在所有部分上显示,但在第一部分中不需要。 How can I hide it? 我怎么藏起来? I tried with js but it didn't work. 我尝试使用js,但是没有用。

<script>
    $(document).ready(function() {
   var windowURL = window.location.href;
   console.log(windowURL);

   if (windowURL.indexOf('index.html#slide1') > -1) {
     $('#burger').css('display', 'none');
   }
});
   </script>

Assuming you are using a button to navigate from the first section since it's not scrollable, you can use 假设您正在使用按钮从第一部分导航,因为该按钮不可滚动,因此可以使用

display: none

on your burger menu by default then use a function that shows the burger menu: 默认情况下,在汉堡菜单上使用显示汉堡菜单的功能:

function showBurger() {
  var burger = document.getElementById("burger");
  burger.classList.add("shown");
}

to the button's on click event, assuming you use another button to navigate back to the first section then you can add another function that removes the burger again to its onclick event: 到按钮的onclick事件,假设您使用另一个按钮导航回第一部分,则可以添加另一个功能,将汉堡再次删除到其onclick事件:

function removeBurger() {
  var burger = document.getElementById("burger");
  burger.classList.remove("shown");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM