簡體   English   中英

更新我的JQuery版本后滾動到div動畫問題

[英]Scroll to div animate Issue after updating my JQuery version

我將jQuery從1.9更新到3.1.1,現在遇到了一個問題: .animate不起作用。

我還添加了遷移插件3.0.0

我的腳本如下:

$(function() {
   $('a.page-scroll').bind('click', function(event) {
      var $anchor = $(this);

      $('html, body').stop().animate({
         scrollTop: $($anchor.attr('href')).offset().top
      }, 1500, 'easeInOutExpo');

      event.preventDefault();
   });
});

嘗試將.bind更改為.on ,因為.bind已被棄用。

也許這會有所幫助。

  1. 加載第一個jQuery
  2. 做剩下的

 </script> <script> $('a[href^="#"]').on('click', function(event) { var target = $(this.getAttribute('href')); if( target.length ) { event.preventDefault(); $('html, body').stop().animate({ scrollTop: target.offset().top }, 1000); } }); </script> 
 .bl{ height:750px; width:100px; background-color: #FF0000; } a{ display:inline-block; height:50px; width:100%; } 
 <script src="https://code.jquery.com/jquery-3.1.1.js" integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA=" crossorigin="anonymous"> </script> <a href="#page-scroll">clickhere to go to anchor</a> <div class="bl">this is dummy div</div> <a id="page-scroll" href="#">moved</a> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM