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

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

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

github地址 https://github.com/iamdustan/smoothscroll

h5代码:

<a href="javascript:void(0)" onclick="gotoTest1()">首页</a>

JS代码

function gotoTest1(){
document.querySelector('#home').scrollIntoView({ behavior: 'smooth' });
}

完整实例

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <title>okayNav Demo</title> <link href="http://fonts.googleapis.com/css?family=Roboto:700,400&subset=latin" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="css/common.min.css">
<link rel="stylesheet" href="css/okayNav.min.css"> </head>
<body> <header id="header" class="okayNav-header">
<a class="okayNav-header__logo" href="#">
Logo
</a> <nav role="navigation" id="nav-main" class="okayNav">
<ul>
<li><a href="javascript:void(0)" onclick="gotoTest1()">首页</a></li>
<li><a href="javascript:void(0)" onclick="gotoTest2()">购物</a></li>
<li><a href="javascript:void(0)" onclick="gotoTest3()">博客</a></li>
<li><a href="javascript:void(0)" onclick="gotoTest4()">服务</a></li>
<li><a href="javascript:void(0)" onclick="gotoTest5()">联系我们</a></li>
<li><a href="javascript:void(0)" onclick="gotoTest6()">关于我们</a></li>
<li><a href="javascript:void(0)" onclick="gotoTest7()">测试</a></li>
</ul>
</nav>
</header><!-- /header --> <main>
<h1 id="home" >Resize your browser to preview okayNav</h1>
</main> <section id="shop" style="min-height:620px;background-color:#777">
<h1 style="padding-top:100px;">shop</h1> </section> <section id="blog" style="min-height:620px;background-color:#236777">
<h1 style="padding-top:100px;">blog</h1> </section> <section id="service" style="min-height:620px;background-color:red">
<h1 style="padding-top:100px;">service</h1> </section> <section id="connect" style="min-height:620px;background-color:#25fb65">
<h1 style="padding-top:100px;">connect</h1> </section> <section id="about" style="min-height:620px;background-color:#66fb65">
<h1 style="padding-top:100px;">about</h1> </section> <section id="test" style="min-height:620px;background-color:#e34565">
<h1 style="padding-top:100px;">test</h1> </section> <script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
<script src="js/jquery.okayNav-min.js"></script>
<script src="js/smoothscroll.js"></script> <script type="text/javascript">
var navigation = $('#nav-main').okayNav();
function gotoTest1(){
document.querySelector('#home').scrollIntoView({ behavior: 'smooth' });
}function gotoTest2(){
document.querySelector('#shop').scrollIntoView({ behavior: 'smooth' });
}function gotoTest3(){
document.querySelector('#blog').scrollIntoView({ behavior: 'smooth' });
}function gotoTest4(){
document.querySelector('#service').scrollIntoView({ behavior: 'smooth' });
}function gotoTest5(){
document.querySelector('#connect').scrollIntoView({ behavior: 'smooth' });
}function gotoTest6(){
document.querySelector('#about').scrollIntoView({ behavior: 'smooth' });
}
function gotoTest7(){
document.querySelector('#test').scrollIntoView({ behavior: 'smooth' });
}
</script>
</body>
</html>

示例图片

最新文章

  1. 基本概念----Beginning Visual C#
  2. jQ中对attr()方法的理解
  3. Network - FTP与SFTP
  4. AC日记——紧急措施 openjudge 1.7 22
  5. android MPAndroidChart饼图实现图例后加数字或文本(定制图例)
  6. java练习题(字符串类):显示4位验证码、输出年月日、从XML中抓取信息
  7. Jmeter使用指南
  8. Xamarin Studio支持TypeScript开发
  9. C语言练习代码
  10. apicloud+融云实现即时通讯
  11. MapReduce扩展:应用程序如何运行于Hadoop Yarn之上
  12. GeeksforGeeks - Adjacency List邻接矩阵C\C++代码
  13. int main(int argc,char *argv[])参数的应用
  14. abp zero sample
  15. HDU 1698 Just a Hook 线段树+lazy-target 区间刷新
  16. html标签对应的英文原文 - 司徒正美
  17. python---- pyqt 十字光标
  18. java_28 序列化与反序列化
  19. html小知识点(220-1)
  20. Mysql优化_慢查询开启说明及Mysql慢查询分析工具mysqldumpslow用法讲解

热门文章

  1. Nginx 转发特点URL到指定服务
  2. HDU 5852 Intersection is not allowed! ( 2016多校9、不相交路径的方案、LGV定理、行列式计算 )
  3. 小米oj 不要乱改代码(并查集)
  4. Linux shell -&quot;a-d&quot;命令
  5. [Cogs] 线型网络
  6. vue-cli 本地代理 造成session丢失 而登录不上去 解决办法
  7. AD域渗透总结
  8. legend3---9、项目的日志以及调试信息数据量非常大
  9. Flutter移动电商实战 --(8)dio基础_伪造请求头获取数据
  10. Failed to execute aapt