简体   繁体   English

如何在滚动导航栏上消失时调整徽标图像的大小

[英]How to size logo image in disappear on scroll navbar

I did not use bootstrap because I couldn't get it to function.我没有使用 bootstrap,因为我无法将它发送到 function。

I've used HTML, CSS, and Javascript. I want to have the logo image be the same size as the nav bar and disappear on scroll.我使用了 HTML、CSS 和 Javascript。我想让徽标图像与导航栏大小相同,并在滚动时消失。 Also, if anyone has suggestions on how to shift the home/ contact/ etc to the right, away from the logo image, that would be great.此外,如果有人对如何将主页/联系人/等向右移动远离徽标图像提出建议,那就太好了。

Here's the code:这是代码:

 /* When the user scrolls down, hide the navbar. When the user scrolls up, show the navbar */ var prevScrollpos = window.pageYOffset; window.onscroll = function() { var currentScrollPos = window.pageYOffset; if (prevScrollpos > currentScrollPos) { document.getElementById("navbar").style.top = "0"; } else { document.getElementById("navbar").style.top = "-50px"; } prevScrollpos = currentScrollPos; }
 #navbar { background-color: #333; /* Black background color */ position: fixed; /* Make it stick/fixed */ top: 0; /* Stay on top */ width: 100%; /* Full width */ transition: top 0.3s; /* Transition effect when sliding down (and up) */ } /* Style the navbar links */ #navbar a { float: left; display: block; color: white; text-align: center; padding: 15px; text-decoration: none; } #navbar a:hover { background-color: #ddd; color: black; }.logo-image img{ width: 46px; height: 46px; border-radius: 50%; overflow: hidden; margin-top: -6px; }
 <div id="navbar"> <a class="navbar-brand" href="images/Besosnbuds.jpg"> <div class="logo-image"> <img src="images/Besosnbuds.jpg" class="img-fluid"> </div> <a href="index.html">Home </a> <a href="about.html">About</a> <a href="contact.html">Contact</a> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"> <a class="social_media" href="https://www.facebook.com/natalie.april.73"><i class="fa fa- fa-facebook-square" aria-hidden="true"></i></a> <a class="social_media" href="https://www.instagram.com/besosnbuds/"><i class="fa fa-instagram" aria-hidden="true"></i> </nav> </div>

To shift the Home, Contact, and About to the right away from the logo image, you should wrap the Home, Contact, and About anchor tags in a, and the same with the logo.要将 Home、Contact 和 About 从徽标图像向右移动,您应该将 Home、Contact 和 About 锚标记包裹在 a 中,与徽标相同。 then wrap those two divs in a containing <div class='container'> .然后将这两个 div 包装在包含<div class='container'>中。 Target container and add目标容器并添加

.container {
  display:flex;
  justify-content:space-between;
  align-content: space-between;
  width: 100%;
}

That should push the logo to the far left and everything else to the right.这应该将徽标推到最左边,将其他所有内容推到右边。

As for getting the logo to disappear when you scroll, try adding至于让徽标在滚动时消失,请尝试添加

document.getElementById("logo-image").style.opacity = "0";

or或者

document.getElementById("logo-image").style.display = "none";

in the else statement.在 else 语句中。

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

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