国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jQuery實現錨點向下平滑滾動特效示例

2019-11-19 15:38:59
字體:
來源:轉載
供稿:網友

實現效果:

實現原理:

使用jQuery animate()方法實現頁面平滑滾動特效

$('html, body').animate({scrollTop: $(hash).offset().top}, 800, function(){window.location.hash = hash;});

簡單實例代碼:

<!DOCTYPE html><html><head><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><script>$(document).ready(function(){ // Add smooth scrolling to all links $("a").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 });});</script> <style>body, html, .main {  height: 100%;} section {  min-height: 100%;}</style></head><body><a href="#section2" rel="external nofollow" style="   font-size: 30px;   font-weight: bold;   text-align: center;">點擊此處平滑滾動到第二部分</a><div class="main"> <section></section></div><div class="main" id="section2"> <section style="   background-color: #03c03c;   color: #fff;   font-size: 30px;   text-align: center">   SECTION 2 </section></div></body></html>

以上這篇jQuery實現錨點向下平滑滾動特效示例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东宁县| 同仁县| 溆浦县| 涟源市| 鱼台县| 许昌县| 金堂县| 汕尾市| 卢龙县| 天等县| 永安市| 高尔夫| 莒南县| 延庆县| 德阳市| 高清| 黄陵县| 博白县| 元氏县| 通化市| 永城市| 海南省| 新巴尔虎右旗| 台东县| 建昌县| 德安县| 长丰县| 兰坪| 五家渠市| 牟定县| 庆云县| 宣汉县| 科技| 惠来县| 托克逊县| 曲沃县| 新营市| 浦县| 铜梁县| 会东县| 盐源县|