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

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

無法使用 Jquery animate 函數(shù)實(shí)現(xiàn)平滑滾動

無法使用 Jquery animate 函數(shù)實(shí)現(xiàn)平滑滾動

手掌心 2022-12-22 14:33:57
伙計們,我試圖在 JQuery 的幫助下在我的網(wǎng)頁上實(shí)現(xiàn)平滑滾動功能。每當(dāng)我單擊導(dǎo)航項(xiàng)時,頁面都應(yīng)滾動到特定部分。但那并沒有發(fā)生。這是我的 index.js 代碼$("#navbar a, .btn").on("click", function (event) {  if (this.hash != "") {    event.preventDefault();    const hash = this.hash;    $("html", "body").animate(      {        scrollTop: $(hash).offset().top - 100,      },      800    );  }});這是網(wǎng)站的鏈接嘗試單擊任何導(dǎo)航項(xiàng)并查看。 https://umakanth-pendyala.github.io/Edge-Ledger/這是我的回購協(xié)議的鏈接 https://github.com/umakanth-pendyala/Edge-Ledger.git任何幫助,將不勝感激。謝謝
查看完整描述

2 回答

?
撒科打諢

TA貢獻(xiàn)1934條經(jīng)驗(yàn) 獲得超2個贊

讓它平穩(wěn)運(yùn)行的一種簡單方法是將毫秒設(shè)置為 0 而不是 800,并將該scroll-behavior: smooth;屬性添加到html標(biāo)記中。

html {scroll-behavior: smooth;}


查看完整回答
反對 回復(fù) 2022-12-22
?
ITMISS

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超8個贊

你可能想嘗試這樣的事情,


$(document).ready(function(){

  // Add smooth scrolling to required elements, here I've considered all the buttons with 

  //class name 'button'

  $(".button").on('click', function(event) {


    // Make sure this.hash has a value before overriding default behavior

    if (this.hash !== "") {

      // Prevent default anchor click behavior

      event.preventDefault();


      // Store hash

      var hash = this.hash;


      // Using jQuery's animate() method to add smooth page scroll

      // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area

      $('html, body').animate({

        scrollTop: $(hash).offset().top

      }, 800, function(){


        // Add hash (#) to URL when done scrolling (default click behavior)

        window.location.hash = hash;

      });

    } // End if

  });

});

或者,為整個文檔添加平滑滾動行為。


html {

  scroll-behavior: smooth;

}


查看完整回答
反對 回復(fù) 2022-12-22
  • 2 回答
  • 0 關(guān)注
  • 121 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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