jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jQuery 插件 smoothscroll大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

smoothscroll是一款jQuery插件,可以平滑地滚动到指定的地方。

可以解决chrome锚点失效的问题。

官方网站 http://iamdustan.com/smoothscroll/

下载源码网站 https://github.com/iamdustan/smoothscroll

css代码

1 <link href="http://fonts.googleapis.com/css?family=Roboto:700,400&subset=laTin" rel="stylesheet" type="text/css">
2     <link rel="stylesheet" href="css/common.min.css">
3     <link rel="stylesheet" href="css/okayNav.min.css">

js代码

function gotoTest1(){
            document.querySELEctor(‘#home‘).scrollIntoView({ behavior: ‘smooth‘ });
        }

完整代码

 
 1 <!doctype html>
 2 <html>
 3 <head>
 4     <Meta charset="UTF-8">
 5     <Meta name="viewport" content="width=device-width,initial-scale=1">
 6 
 7     <title>平滑滚动</title>
 8 
 9     <link href="http://fonts.googleapis.com/css?family=Roboto:700,400&subset=laTin" rel="stylesheet" type="text/css">
10     <link rel="stylesheet" href="css/common.min.css">
11     <link rel="stylesheet" href="css/okayNav.min.css">
12     
13     
14 </head>
15 <body>
16 
17     <header id="header" class="okayNav-header">
18         <a class="okayNav-header__logo" href="#">
19            logo
20         </a>
21 
22         <nav role="navigation" id="nav-main" class="okayNav">
23             <ul>
24                 <li><a href="#">首页</a></li>
25                 <li><a href="#shop">购物</a></li>
26                 <li><a href="#blog">博客</a></li>
27                 <li><a href="#service">服务</a></li>
28                 <li><a href="#connect">联系我们</a></li>
29                 <li><a href="#about">关于我们</a></li>
30                 <li><a href="javascript:void(0)" onclick="gototest()">测试</a></li>
31             </ul>
32         </nav>
33     </header><!-- /header -->
34 
35     <main>
36         <h1>Resize your browser to preview okayNav</h1>
37     </main>
38     
39     
40     <section id="shop" style="min-height:700px; padding: 0px; color: rgb(0,255); line-height: 1.5 !important;">>
41     <h1>shop</h1>
42     
43     </section>
44     
45     
46     <section id="blog" style="min-height:700px; padding: 0px; color: rgb(0,255); line-height: 1.5 !important;">>
47     <h1>blog</h1>
48     
49     </section>    
50     
51     
52     <section id="service" style="min-height:700px; padding: 0px; color: rgb(0,255); line-height: 1.5 !important;">>
53     <h1>service</h1>
54     
55     </section>    
56         
57     <section id="connect" style="min-height:700px; padding: 0px; color: rgb(0,255); line-height: 1.5 !important;">>
58     <h1>connect</h1>
59     
60     </section>    
61     
62     <section id="about" style="min-height:700px; padding: 0px; color: rgb(0,255); line-height: 1.5 !important;">>
63     <h1>about</h1>
64     
65     </section>        
66     
67     <section id="test" style="min-height:700px; padding: 0px; color: rgb(0,255); line-height: 1.5 !important;">>
68     <h1>test</h1>
69     
70     </section>        
71     
72     <script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
73     <script src="js/jquery.okayNav-min.js"></script>
74     <script src="js/smoothscroll.js"></script>
75 
76     <script type="text/javascript">
77         var navigation = $(‘#nav-main‘).okayNav();
78         
79         function gototest(){
80             document.querySELEctor(‘#test‘).scrollIntoView({ behavior: ‘smooth‘ });
81         }
82     </script>
83 </body>
84 </html>
 

运行结果:

jQuery 插件 smoothscroll

大佬总结

以上是大佬教程为你收集整理的jQuery 插件 smoothscroll全部内容,希望文章能够帮你解决jQuery 插件 smoothscroll所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。