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>

示例图片

smoothscroll的更多相关文章

  1. 页面中的平滑滚动——smooth-scroll.js的使用

    正常的本页面锚链接跳转的时候跟PPT似的,特别生硬,用户体验非常差. 这时候我们就可以借助smooth-scroll.js这个插件,来实现本页面的平滑的跳转. 1首先,导入必须的JS文件 <sc ...

  2. 踩石行动:ViewPager无限轮播的坑

    2016-6-19 前言 View轮播效果在app中很常见,一想到左右滑动的效果就很容易想到使用ViewPager来实现.对于像我们常说的banner这样的效果,具备无限滑动的功能是可以用ViewPa ...

  3. zepto返回顶部动画

    点击返回顶部 function goTop(acceleration, time) { acceleration = acceleration || 0.1; time = time || 16; v ...

  4. js实现返回顶部功能的解决方案

    很多网站上都有返回顶部的效果,主要有如下几种解决方案. 1.纯js,无动画版本 window.scrollTo(x-coord, y-coord); window.scrollTo(0,0); 2.纯 ...

  5. ViewPager取消左右滑动切换功能

    ViewPager取消左右滑动切换功能 最近做项目要求某种情况下ViewPager不能滑动,那么我们只需要重写这个方法就可以禁止ViewPager滑动 IndexViewPager.java: imp ...

  6. jquery.nicescroll完美滚动条使用方法

    配置参数 当调用"niceScroll"你可以传递一些参数来定制视觉方面: cursorcolor - 十六进制改变光标颜色,默认值是"#000000" cur ...

  7. 微软专家推荐11个Chrome 插件

    Web开发人员,需要长时间使用浏览器,尽管Windows10 Edge浏览器启动非常快速,且支持110多种设备,Edge支持基于JS 扩展,但也删除了很多旧功能像Active-X等插件.多数情况下,插 ...

  8. 前端那点事儿——Tocify自动生成文档目录

    今天偶然间看到文档服务器有一个动态目录功能,点击目录能跳转到指定的位置:窗口滑动也能自动更新目录的焦点. 效果 框架 原来使用的是一个开源的jquery-ui控件——tocify.js,它可以遍历页面 ...

  9. jQuery Tocify 定位导航

    Tocify是一个jQuery插件,能够动态的生成文章目录,Tocify可以随意的设置Twitter Bootstrap 或者 jQueryUI Themeroller支持的可选动画和jQuery的显 ...

随机推荐

  1. Laravel Passport API 认证使用小结

    Laravel Passport API 认证使用小结 八月 4, 2017 发布在 Laravel 看到Laravel-China 社区常有人问 Laravel Passport 用于密码验证方式来 ...

  2. 強悍的Linq

    在使用Linq轉化XML,ActiveDirectory,Datatable,Array,List,Dictionary后意識到Linq的強大.VS居然還提供專門的LINQ Explorer,不覺明厲 ...

  3. 我关了solution并且删掉个sln.DotSettings.user后似乎也可以了

    "Go To Definition" is disabled in Visual Studio http://social.msdn.microsoft.com/Forums/en ...

  4. Digit Division(排列组合+思维)(Gym 101480D )

    题目链接:Central Europe Regional Contest 2015 Zagreb, November 13-15, 2015 D.Digit Division(排列组合+思维) 题解: ...

  5. Python面试题:使用栈处理括号匹配问题

    括号匹配是栈应用的一个经典问题, 题目 判断一个文本中的括号是否闭合, 如: text = "({[({{abc}})][{1}]})2([]){({[]})}[]", 判断所有括 ...

  6. Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)

    Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...

  7. POJ 1144 Network —— (找割点)

    这是一题找无向图的割点的模板题,割点的概念什么的就不再赘述了.这里讲一下这个模板的一个注意点. dfs中有一个child,它不等于G[u].size()!理由如下: 如上图,1的size是2,但是它的 ...

  8. redis的哨兵

    删除旧master或者不可达slave sentinel永远会记录好一个Master的slaves,即使slave已经与组织失联好久了.这是很有用的,因为sentinel集群必须有能力把一个恢复可用的 ...

  9. JS基础_垃圾回收(GC)

    垃圾回收(GC) 程序运行过程中也会产生垃圾,这些垃圾积攒过多以后,会导致程序运行的速度过慢,所以我门需要一个垃圾回收的机制,来处理程序运行过程中产生的垃圾 当一个对象没有任何的变量或属性对它进行引用 ...

  10. 宝塔安装Nextcloud,挂载在阿里云oss上,打造个人/企业高效私有云盘

    如下未完整整理,看懂看不懂随缘.... 准备条件: 1.阿里云oss 2.阿里云ecs 3.环境:centos7.x 步骤: 1.centos中安装宝塔面板 2.下载NextCloud安装包,上传到宝 ...