最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery實(shí)現(xiàn)錨點(diǎn)向下平滑滾動(dòng)特效示例

 更新時(shí)間:2017年08月29日 07:47:13   作者:Dragonir  
下面小編就為大家?guī)?lái)一篇jQuery實(shí)現(xiàn)錨點(diǎn)向下平滑滾動(dòng)特效示例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

實(shí)現(xiàn)效果:

實(shí)現(xiàn)原理:

使用jQuery animate()方法實(shí)現(xiàn)頁(yè)面平滑滾動(dòng)特效

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

簡(jiǎn)單實(shí)例代碼:

<!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;
">點(diǎn)擊此處平滑滾動(dòng)到第二部分</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實(shí)現(xiàn)錨點(diǎn)向下平滑滾動(dòng)特效示例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

邮箱| 北安市| 营山县| 沙湾县| 马山县| 陇川县| 东乌珠穆沁旗| 舒兰市| 塔城市| 汾阳市| 和顺县| 娱乐| 天台县| 建始县| 丹凤县| 长顺县| 新乡县| 江达县| 色达县| 浦江县| 余姚市| 广丰县| 徐州市| 东乡县| 安泽县| 石阡县| 雷州市| 金坛市| 昭通市| 满洲里市| 兴海县| 双江| 遵义县| 焉耆| 贵州省| 界首市| 商南县| 曲阜市| 砀山县| 潼南县| 阿克苏市|