您好,登錄后才能下訂單哦!
實(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è)參考,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。