• Javascript实现导航锚点滚动效果实例


    <!DOCTYPE html>
    <html>

        <head>
            <meta charset="{CHARSET}">
            <title></title>
            <script src="jquery.1.8.3.html"></script>
            <style>
                .section{
                    
                    height:200px;
                     100%;
                }
                #section1{
                    background: red;
                }
                #section2{
                    background: blue;
                }
                #section3{
                    background: gold;
                }
                #section4{
                    background: green;
                }
                #section5{
                    background: cyan;
                }
                nav{ position: fixed; 100px; right: 10px; top: 20px;}
            </style>
        </head>

        <body>
            <p class="container">
                <p class="wrapper">
                    <p class="section" id="section1">section1</p>
                    <p class="section" id="section2">section2</p>
                    <p class="section" id="section3">section3</p>
                    <p class="section" id="section4">section4</p>
                    <p class="section" id="section5">section5</p>
                </p>
                <nav>
                    <a href="#section1" rel="external nofollow" class="current">section1</a>
                    <a href="#section2" rel="external nofollow">section2</a>
                    <a href="#section3" rel="external nofollow">section3</a>
                    <a href="#section4" rel="external nofollow">section4</a>
                    <a href="#section5" rel="external nofollow">section5</a>
                </nav>
            </p>
        </body>
        <script>

    //这个和下面代码可以选择一种
    //  var $navs = $('nav a'),          // 导航
    //$sections = $('.section'),       // 模块
    //$window = $(window),
    //navLength = $navs.length - 1;
    //
    //$window.on('scroll', function() {
    //var scrollTop = $window.scrollTop(),
    //  len = navLength;
    //
    //for (; len > -1; len--) {
    //  var that = $sections.eq(len);
    //  if (scrollTop >= that.offset().top) {
    //     $navs.removeClass('current').eq(len).addClass('current');
    //     break;
    //  }
    //}

    $navs.on('click', function(e) {
      e.preventDefault();
      $('html, body').animate({
        'scrollTop': $($(this).attr('href')).offset().top
      }, 400);
    });
        </script>

    </html>

  • 相关阅读:
    Sql2000存储过程分页
    扇贝网页记单词插件
    notepad++正则替换保留原内容
    给 QuickTime 播放器添加快进x秒,快退x秒
    谷歌浏览器隐私设置错误 NET::ERR_CERT_AUTHORITY_INVALID 攻击者可能会试图从 xx 窃取您的信息(例如:密码、通讯内容或信用卡信息)。
    Java实体映射工具MapStruct 与BeanUtils性能比较
    阿里DDD项目最佳实践-COLA 架构总览
    Java实体映射工具MapStruct详解
    Martin Fowler大神
    领域模型的核心本质是什么?
  • 原文地址:https://www.cnblogs.com/gerry/p/7519428.html
Copyright © 2020-2023  润新知