亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

如何使用jQuery向上或向下滾動頁面到錨點?

如何使用jQuery向上或向下滾動頁面到錨點?

互換的青春 2019-07-25 18:53:43
如何使用jQuery向上或向下滾動頁面到錨點?我正在尋找一種方法來包含幻燈片效果,當您單擊頁面上或下的本地錨點鏈接時。我想要一個你有這樣一個鏈接的東西:<a href="#nameofdivetc">link text, img etc.</a>也許添加了一個類,所以你知道你希望這個鏈接是一個滑動鏈接:<a href="#nameofdivetc" class="sliding-link">link text, img etc.</a>然后,如果單擊此鏈接,頁面將向上或向下滑動到所需位置(可以是div,標題,頁面頂部等)。這就是我以前的情況:    $(document).ready(function(){     $(".scroll").click(function(event){         //prevent the default action for the click event         event.preventDefault();         //get the full url - like mysitecom/index.htm#home         var full_url = this.href;         //split the url by # and get the anchor target name - home in mysitecom/index.htm#home         var parts = full_url.split("#");         var trgt = parts[1];         //get the top offset of the target anchor         var target_offset = $("#"+trgt).offset();         var target_top = target_offset.top;         //goto that anchor by setting the body scroll top to anchor top         $('html, body').animate({scrollTop:target_top}, 1500, 'easeInSine');     });});
查看完整描述

3 回答

  • 3 回答
  • 0 關注
  • 762 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號