简体   繁体   English

缩小和固定的导航栏间隙

[英]Shrinking & fixed navbar gap

I've got a header composed of a small navbar and of a big one, which is the main one. 我有一个标头,它由一个小导航栏和一个大导航栏组成,这是主要的导航栏。

To the main one, I've did it so that it sticks to the page and it shrinks while scrolling, but for a second it goes like this — I don't know how to explain it: https://imgur.com/a/NcfyC 最主要的是,我这样做是为了使其贴在页面上并在滚动时缩小,但是有一秒钟它是这样的—我不知道如何解释: https//imgur.com/ a / NcfyC

The second picture is the default, when it is not scrolled, and the first picture is when a gap appears for a second, but after that goes back to normal. 第二张图片是默认图片(不滚动时),而第一张图片是空白出现一秒钟之后的图片,但此后又恢复了正常。 I really don't get why this happens. 我真的不明白为什么会这样。

Here's how I did it: 这是我的操作方式:

 $(window).scroll(function() { if ($(this).scrollTop() > 50) { $('#top-mare-wrap').addClass("shrink"); } else { $('#top-mare-wrap').removeClass("shrink"); } }); 
 #top-mare-wrap.shrink { top: 0; margin: 0; padding: 0; } #top-mare-wrap.shrink ul { margin-left: auto; margin-right: auto; } #top-mare-wrap.shrink li { margin-left: auto; margin-right: auto; } #top-mare-wrap.shrink img { position: relative; left: 7vw; width: 6vw; } #top-mare-wrap.shrink a { margin: 0; padding: 0; left: 20vw; top: 0.8vw; } #top-mare-wrap.shrink a:hover:after { width: 100%; color: #F28A00; } #top-mare-wrap { position: fixed; width: 100%; background: #fff; border-bottom: 0.2vw solid orange; transition: all .5s ease-in-out; z-index: 100; } #top-mare { padding: 0; margin: 0; padding-bottom: 1.55vw; } #top-mare ul { list-style-type: none; margin: 0; padding: 0; } #top-mare li { display: inline; padding-left: 4vw; } #top-mare a { position: relative; } #top-mare a:after { content: ''; position: absolute; bottom: 0; left: 0; width: 0%; border-bottom: 2px solid #F28A00; transition: 0.4s ease; } #top-mare a:hover:after { width: 74%; color: #F28A00; } #top-mare a:hover { color: #F28A00; } #top-mare li a { margin-top: 1.3vw; margin-left: 3.083vw; padding-right: 1.041vw; display: inline-block; text-decoration: none; color: #ADADAD; text-align: center; font-size: 1vw; font-weight: normal; } .slideshow-container { clear: both; max-width: 100%; position: relative; margin: auto; overflow: hidden; z-index: 10; } .rslides { position: relative; list-style: none; overflow: hidden; width: 100%; padding: 0; margin: 0; } .rslides li { -webkit-backface-visibility: hidden; position: relative; display: none; width: 100%; left: 0; top: 0; } .rslides li:first-child { position: relative; display: block; float: left; } .rslides img { display: block; height: auto; float: left; width: 100%; border: 0; } 
 <header id="top"> <nav id="top-mic"> <ul> <li class="dreapta"><a href="#">Contact</a></li> <li class="dreapta"><a href="#">Despre noi</a></li> <li class="dreapta"><a href="#">Locatie</a></li> <li class="stanga"><img src="img/phone.jpg" class="phone" />074 44 44 444</li> <li class="stanga mail-text"><img src="img/mail.jpg" class="mail" />bestdavnic73@gmail.com</li> <li class="stanga"> <a href="http://facebook.com" target="_blank"><img src="img/facebook.jpg" class="fb" /></a> </li> </ul> </nav> <div id="top-mare-wrap"> <a href="#"><img src="img/logo.jpg" alt="davnic" class="logo"></img> </a> <nav id="top-mare"> <ul> <li><a href="#">Acasa</a></li> <li><a href="#">Buton1</a></li> <li><a href="#">Buton2</a></li> <li><a href="#">Buton3</a></li> <li><a href="#">Buton4</a></li> </ul> </nav> </div> </header> </div> <div class="slideshow-container"> <ul class="rslides"> <li><img src="img/img1.jpg" alt=""></li> <li><img src="img/img2.jpg" alt=""></li> <li><img src="img/img3.jpg" alt=""></li> </ul> <script src="js/sshow.js"></script> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

Oh I solved it by myself - I had to position the pic from the slideshow in another way. 哦,我自己解决了-我不得不以另一种方式放置幻灯片中的图片。 Added top: 4.16vw, now works fine. 新增顶部:4.16vw,现在可以正常工作。

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

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