Скрытая боковая панель навигации - PullRequest
1 голос
/ 06 апреля 2020

Я пытаюсь создать навигационную панель, которая прячется при прокрутке вниз, а затем раскрывает себя только при наведении на нее, любая помощь будет принята. успех, поэтому я просто пропустил этот код.

Относительно новый и просто пытаюсь что-то выяснить, извините, если мой пост не очень четкий или не в правильном формате.

@charset "UTF-8";
#mySidenav a {
  position:fixed;
  right: -10px;
  transition: 0.7s;
  padding: 15px;
  width: 100px;
  text-decoration: none;
  text-align: center;
  font-size: 20px;
  color: white;
  border-radius: 5px 0 0px 5px;
  opacity: .5;
}


#mySidenav a:hover {
  right: 0;
  opacity: 1;
}

#about {
  top: 20px;
  background-color: #4CAF50;
}

#blog {
  top: 80px;
  background-color: #2196F3;
}

#projects {
  top: 140px;
  background-color: #f44336;
}

#contact {
  top: 200px;
  background-color: #555
}
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Untitled Document</title>
<link href="Web Site CSS.css" rel="stylesheet" type="text/css">
</head>
	
<body>
<div id="mySidenav" class="sidenav">
  <a href="#" id="about">About</a>
  <a href="#" id="blog">Exhibitions</a>
  <a href="#" id="projects">Past Work</a>
  <a href="#" id="contact">Social Info</a>
</div>
	
<div style="padding:15px 15px 2500px;font-size:30px;margin-top:30px;">
  <p><b>Looking to hide the nav bar when scrolled down and if the page isn't at the top</b></p>
  <p>Scroll down to understand what I'm meaning</p>
  <p>Also looking to make it slide out when hovered over </p>
  <p>Lorem ipsum dolor dummy text sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
  <p>Lorem ipsum dolor dummy text sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
	
	<script>
var prevScrollpos = window.pageYOffset;
window.onscroll = function() {
var currentScrollPos = window.pageYOffset;
  if (prevScrollpos > currentScrollPos) {
    document.getElementById("about").style.right = "-10px";
	document.getElementById("blog").style.right = "-10px";
	document.getElementById("projects").style.right = "-10px";
	document.getElementById("contact").style.right = "-10px";
  } else {
    document.getElementById("about").style.right = "-100px";
	document.getElementById("blog").style.right = "-100px";
	document.getElementById("projects").style.right = "-100px";
	document.getElementById("contact").style.right = "-100px";
  }
  prevScrollpos = currentScrollPos;
}
	</script>	
</body>	
</html>

Ответы [ 2 ]

0 голосов
/ 06 апреля 2020

Просто попробуйте это:

@charset "UTF-8";
#mySidenav a {
  position:fixed;
  right: -10px;
  transition: 0.7s;
  padding: 15px;
  width: 100px;
  text-decoration: none;
  text-align: center;
  font-size: 20px;
  color: white;
  border-radius: 5px 0 0px 5px;
  opacity: .5;
}


#mySidenav a:hover {
right: 0 !important;
opacity: 1;
   }

#about {
  top: 20px;
  background-color: #4CAF50;
}

#blog {
  top: 80px;
  background-color: #2196F3;
}

#projects {
  top: 140px;
  background-color: #f44336;
}

#contact {
  top: 200px;
  background-color: #555
}
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Untitled Document</title>
<link href="Web Site CSS.css" rel="stylesheet" type="text/css">
</head>
	
<body>
<div id="mySidenav" class="sidenav">
  <a href="#" id="about">About</a>
  <a href="#" id="blog">Exhibitions</a>
  <a href="#" id="projects">Past Work</a>
  <a href="#" id="contact">Social Info</a>
</div>
	
<div style="padding:15px 15px 2500px;font-size:30px;margin-top:30px;">
  <p><b>Looking to hide the nav bar when scrolled down and if the page isn't at the top</b></p>
  <p>Scroll down to understand what I'm meaning</p>
  <p>Also looking to make it slide out when hovered over </p>
  <p>Lorem ipsum dolor dummy text sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
  <p>Lorem ipsum dolor dummy text sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
	
	<script>
var prevScrollpos = window.pageYOffset;
window.onscroll = function() {
var currentScrollPos = window.pageYOffset;
  if (prevScrollpos > currentScrollPos) {
    document.getElementById("about").style.right = "-10px";
	document.getElementById("blog").style.right = "-10px";
	document.getElementById("projects").style.right = "-10px";
	document.getElementById("contact").style.right = "-10px";
  } else {
    document.getElementById("about").style.right = "-100px";
	document.getElementById("blog").style.right = "-100px";
	document.getElementById("projects").style.right = "-100px";
	document.getElementById("contact").style.right = "-100px";
  }
  prevScrollpos = currentScrollPos;
}
	</script>	
</body>	
</html>

Какие изменения были внесены мной в ваш код?

Я использую только важные свойства для решения вашей проблемы

Я заменяю это: right: 0; На это: right: 0 !important;.

Надеюсь, это поможет вам, спасибо .

0 голосов
/ 06 апреля 2020

добавить !important right свойство на #mySidenav a:hover

#mySidenav a:hover {
  right: 0 !important;
  opacity: 1;
}

https://jsfiddle.net/lalji1051/w9u5bfL7/2/

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...