第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

更改滾動條上的導(dǎo)航欄

更改滾動條上的導(dǎo)航欄

慕勒3428872 2023-12-11 10:45:23
當(dāng)從頂部滾動大于 20 時,我想更改導(dǎo)航欄。我的代碼可以工作,但是當(dāng)緩慢向上滾動時會無限跳轉(zhuǎn)。我該如何修復(fù)它?工作https://jsfiddle.net/gwuh4zc9/2/這是我的html:<!--Navbar--><div class="container-fluid shadow-sm bg-white">    <div class="container p-0">        <!--First Nav-->        <div class="Nav1 Z-index d-none d-sm-block">            <nav class="navbar navbar-expand-sm navbar-light p-0 py-1">                Nav 1            </nav>        </div>        <!--Second Navbar-->        <div class="Nav2 container-fluid Fixed d-none Z-index bg-white">            <div class="container p-0">                <nav class="navbar p-0 m-0 navbar-expand-sm bg-white navbar-light">                    Nav 2                </nav>            </div>        </div>    </div></div><div class="body">    Body</div>這是我的js代碼:$(document).ready(function() {    $(document).scroll(function() {        if ($(this).scrollTop() > 20) {            $(".Nav1").addClass("d-none");            $(".Nav1").removeClass("d-sm-block");            $(".Nav2").addClass("d-sm-block");        } else {            $(".Nav1").removeClass("d-none");            $(".Nav1").addClass("d-sm-block");            $(".Nav2").removeClass("d-sm-block");        }    })})
查看完整描述

1 回答

?
一只名叫tom的貓

TA貢獻1906條經(jīng)驗 獲得超3個贊

發(fā)生這種情況是因為當(dāng)您將Nav1display 設(shè)置為 none 時,它會從 DOM 中刪除并且scrollTop值會發(fā)生變化。相反,你可以用不透明度隱藏它:


.hidden {

  opacity: 0;

}

并添加/刪除此類:


if ($(this).scrollTop() > 20) {

  $(".Nav1").addClass("hidden");

  $(".Nav2").addClass("nav-visible");

} else {

  $(".Nav1").removeClass("hidden");

  $(".Nav2").removeClass("nav-visible");

}



$(document).ready(function() {

  $(document).scroll(function() {

    if ($(this).scrollTop() > 20) {

      $(".Nav1").addClass("hidden");

      $(".Nav2").addClass("nav-visible");

    } else {

      $(".Nav1").removeClass("hidden");

      $(".Nav2").removeClass("nav-visible");

    }

  })

})

.Z-index {

  z-index: 999999 !important;

}


.nav-initial {

  position: fixed !important;

  right: 0;

  left: 0;

  top: -20px;

  opacity: 0;

  transition: 0.2s;

}


.nav-visible {

  top: 0;

  opacity: 1;

}


.body {

  height: 1000px;

}


.hidden {

  opacity: 0;

}



/* Extra small devices (phones, 600px and down) */


@media only screen and (max-width: 575px) {

  .SearchBox {

    width: 100%;

  }

  .mycard {

    width: 180px;

  }

  .Dotted:before {

    height: 75px;

  }

  .tagFilters {

    height: 3rem;

    width: 6rem;

    font-size: 9pt;

  }

  .wordFilter {

    font-size: 9pt;

  }

  .HotelBckImg {

    height: 230px;

    border-top-left-radius: 15px;

    border-bottom-right-radius: 0;

    margin-bottom: 5px;

  }

  .sm-Padding {

    max-width: 95% !important;

    margin-right: auto;

    margin-left: auto;

  }

  .customButton2 {

    height: 2.8rem;

  }

}


@media only screen and (max-width: 425px) {

  .Dotted:before {

    height: 95px;

  }

}


@media only screen and (max-width: 350px) {

  .Dotted:before {

    height: 125px;

  }

}



/* Small devices (portrait tablets and large phones, 600px and up) */


@media only screen and (min-width: 576px) {

  .SearchBox {

    width: 320px;

  }

  .mycard {

    width: 190px;

  }

  .Dotted:before {

    height: 70px;

  }

  .tagFilters {

    height: 3rem;

    width: 6rem;

    font-size: 9pt;

  }

  .wordFilter {

    font-size: 10pt;

  }

}



/* Medium devices (landscape tablets, 768px and up) */


@media only screen and (min-width: 768px) {

  .SearchBox {

    width: 330px;

  }

  .mycard {

    width: 190px;

  }

  .sideImgLeft {

    width: 30%;

    height: 350px;

    margin-top: 3.5%;

  }

  .sideImgRight {

    width: 30%;

    height: 350px;

    margin-top: 3.5%;

  }

  .Dotted:before {

    height: 90px;

  }

  .tagFilters {

    height: 3rem;

    width: 6rem;

    font-size: 9pt;

  }

  .wordFilter {

    font-size: 9pt;

  }

}



/* Large devices (laptops/desktops, 992px and up) */


@media only screen and (min-width: 992px) {

  .SearchBox {

    width: 400px;

  }

  .mycard {

    width: 190px;

  }

  .sideImgLeft {

    width: 30%;

    height: 370px;

    margin-top: 2%;

  }

  .sideImgRight {

    width: 30%;

    height: 370px;

    margin-top: 2%;

  }

  .tagFilters {

    height: 3rem;

    width: 6rem;

  }

  .wordFilter {

    font-size: 10pt;

  }

}



/* Extra large devices (large laptops and desktops, 1200px and up) */


@media only screen and (min-width: 1200px) {

  .SearchBox {

    width: 370px;

  }

  .mycard {

    width: 190px;

  }

  .sideImgLeft {

    width: 30%;

    height: 285px;

  }

  .sideImgRight {

    width: 30%;

    height: 285px;

  }

  .Dotted:before {

    height: 70px;

  }

  .tagFilters {

    height: 3.3rem;

    width: 8rem;

  }

  .wordFilter {

    font-size: 11pt;

  }

}


.body {

  height: 1000px;

}

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css" rel="stylesheet"/>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<!--Navbar-->

<div class="container-fluid shadow-sm bg-white">

  <div class="container p-0">

    <!--First Nav-->

    <div class="Nav1 Z-index d-none d-sm-block">

      <nav class="navbar navbar-expand-sm navbar-light p-0 py-1">

        Nav 1

      </nav>

    </div>

    <!--Second Navbar-->

    <div class="Nav2 container-fluid nav-initial Z-index bg-white">

      <div class="container p-0">

        <nav class="navbar p-0 m-0 navbar-expand-sm bg-white navbar-light">

          Nav 2

        </nav>

      </div>

    </div>

  </div>

</div>

<div class="body">

  Body

</div>


查看完整回答
反對 回復(fù) 2023-12-11
  • 1 回答
  • 0 關(guān)注
  • 143 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號