码迷,mamicode.com
首页 > Web开发 > 详细

jQuery 插件 smoothscroll

时间:2019-06-19 23:15:19      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:nts   tle   ini   text   var   name   smo   font   doc   

可以解决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; line-height: 1.5; color: rgb(0, 0, 255);">>
41     <h1>shop</h1>
42     
43     </section>
44     
45     
46     <section id="blog" style="min-height:700px; padding: 0px; line-height: 1.5; color: rgb(0, 0, 255);">>
47     <h1>blog</h1>
48     
49     </section>    
50     
51     
52     <section id="service" style="min-height:700px; padding: 0px; line-height: 1.5; color: rgb(0, 0, 255);">>
53     <h1>service</h1>
54     
55     </section>    
56         
57     <section id="connect" style="min-height:700px; padding: 0px; line-height: 1.5; color: rgb(0, 0, 255);">>
58     <h1>connect</h1>
59     
60     </section>    
61     
62     <section id="about" style="min-height:700px; padding: 0px; line-height: 1.5; color: rgb(0, 0, 255);">>
63     <h1>about</h1>
64     
65     </section>        
66     
67     <section id="test" style="min-height:700px; padding: 0px; line-height: 1.5; color: rgb(0, 0, 255);">>
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

标签:nts   tle   ini   text   var   name   smo   font   doc   

原文地址:https://www.cnblogs.com/lszw/p/11055598.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!