萎缩&固定导航栏间隙

时间:2017-11-18 15:27:38

标签: javascript jquery html css

我有一个由小导航栏和一个大导航栏组成的标题,这是主要栏目。

对于主要的一个,我已经这样做了它以便它粘在页面上并且在滚动时缩小,但是一秒钟它就像这样 - 我不知道如何解释它: https://imgur.com/a/NcfyC

第二张图片是默认的,当它没有滚动时,第一张图片是一个间隙出现一秒钟,但之后又恢复正常。我真的不知道为什么会这样。

以下是我的表现:



$(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>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

哦,我自己解决了 - 我不得不以另一种方式从幻灯片中定位图片。添加顶部:4.16vw,现在工作正常。