zoukankan      html  css  js  c++  java
  • smoothscroll

    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>
    

     示例图片

  • 相关阅读:
    在ASP.NET页面中推荐使用覆写(Override)而不是事件处理(Event Handler)[转帖]
    box2dweb资料
    两个游戏开发相关的工具
    django中实现图片上传
    html5和webgame开发
    我的js游戏小引擎 —— 可使用canvas模式或DOM模式
    如何处理网络游戏网络延迟问题
    iphone5和ios6 对html5、web app带来的影响
    矩阵变化和坐标
    连连看游戏demo
  • 原文地址:https://www.cnblogs.com/max-hou/p/10964330.html
Copyright © 2011-2022 走看看