网站侧边功能导航栏--屏幕滚动效果

87 篇文章 0 订阅
27 篇文章 0 订阅

屏幕滚动效果:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        ul,ol {
            list-style-type: none;
        }
        * {margin:0;padding:0;}
        html,body {
            width: 100%;
            height: 100%;
        }
        #ul {
            width: 100%;
            height: 100%;
        }
        ul li{
            width: 100%;
            height: 100%;
        }
        #ol {
            position: fixed;
            top:0;
            left:50px;
        }
        #ol li {
            width: 50px;
            height: 50px;
            border: 1px solid #000;
        }
    </style>
    <script src="my.js" type="text/javascript"></script>
    <script>
        window.onload = function() {
            var ulBox = $("ul");
            var ulBoxLi = ulBox.children;
            var olBox = $("ol");
            var olBoxLi = olBox.children;
            var bgColor = ["pink","purple","orange","blue","green"];
            var leader = 0,target = 0,timer = null;
            for(var i= 0; i<ulBoxLi.length; i++)
            {
                ulBoxLi[i].style.backgroundColor = bgColor[i];
                olBoxLi[i].style.backgroundColor = bgColor[i];
                olBoxLi[i].index = i;  // 记录当前的索引号
                olBoxLi[i].onclick = function() {
                    clearInterval(timer);
                    target = ulBoxLi[this.index].offsetTop; // 核心语句
                    timer = setInterval(function() {
                        leader = leader + (target - leader ) /10;
                        window.scrollTo(0,leader); // 屏幕滑动
                        //pic.style.left = leader  + 'px';
                    },30)
                }
            }
        }
    </script>
</head>
<body>
<ul id="ul">
    <li>首页</li>
    <li>关注</li>
    <li>动态</li>
    <li>风格</li>
    <li>作品</li>
</ul>
<ol id="ol">
    <li>首页</li>
    <li>关注</li>
    <li>动态</li>
    <li>风格</li>
    <li>作品</li>
</ol>
</body>
</html>

这里写图片描述

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值