zoukankan      html  css  js  c++  java
  • 京东之楼层跳跃

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
    * {
    margin: 0;
    padding: 0;
    list-style: none;
    }
    html,body,ul,ul li {
    100%;
    height: 100%;
    }
    ul li {
    font: 600 100px/400px "simsun";
    text-align: center;
    }
    ol {
    position: fixed;
    left: 30px;
    top: 60px;
    }
    ol li {
    100px;
    height: 26px;
    border: 1px solid #000;
    margin-top: -1px;
    text-align: center;
    cursor: pointer;
    }
    </style>
    </head>
    <body>
    <ul>
    <li>服饰美妆</li>
    <li>家电手机</li>
    <li>电脑数码</li>
    <li>3C运动</li>
    <li>母婴家居</li>
    <li>图书汽车</li>
    </ul>
    <ol>
    <li>服饰美妆</li>
    <li>家电手机</li>
    <li>电脑数码</li>
    <li>3C运动</li>
    <li>母婴家居</li>
    <li>图书汽车</li>
    </ol>
    <script src="../toolkit.js"></script>
    <script>
    var ul = document.getElementsByTagName("ul")[0];
    var ulLiArr = ul.children;
    var ol = document.getElementsByTagName("ol")[0];
    var olLiArr = ol.children;
    var colors = ["red","skyblue","green","brown","orange","pink"];
    var leader =0;
    var timer = null;
    var target = 0;
    window.onscroll = function(){
    leader = scroll().top;
    }
    for(var i=0;i<olLiArr.length;i++){
    olLiArr[i].index = i;
    ulLiArr[i].style.backgroundColor=colors[i];
    olLiArr[i].style.backgroundColor=colors[i];
    olLiArr[i].onclick = function(){
    target = ulLiArr[this.index].offsetTop;
    clearInterval(timer);
    timer = setInterval(function(){
    //计算步长
    var step = (target - leader)/10;
    //步长二次处理吧
    step = step >0 ? Math.ceil(step):Math.floor(step);
    //赋值
    leader+= step;
    console.log(1);
    window.scrollTo(0,leader);
    if(target === leader){
    clearInterval(timer);
    }
    },20);
    }
    }
    </script>
    </body>
    </html>

    引入toolkit.js代码内容:
    function scroll(){
    var scroll = {
    top: window.pageYOffset || document.documentElement.scrollTop,
    left: window.pageXOffset || document.documentElement.scrollLeft
    }
    return scroll;
    }


    function animate(ele,target){
    clearInterval(ele.timer);
    ele.timer = setInterval(function(){
    //1.获取步长
    var step = (target -ele.offsetLeft)/10;
    //2.二次处理步长
    step = step>0? Math.ceil(step):Math.floor(step);
    //3、
    ele.style.left = ele.offsetLeft+ step +"px";
    console.log(1);
    if(Math.abs(target -ele.offsetLeft)<=Math.abs(step)){
    clearInterval(ele.timer);
    ele.style.left = target + "px";
    }
    },20);
    }


    function client(){
    return {
    "width": window.innerWidth || document.documentElement.clientWidth,
    "height": window.innerWidth ||document.documentElement.clientWidth,
    }
    }

    function changeColor(){
    if(client().width>960){
    document.body.style.backgroundColor="blue";
    }else if(client().width>640){
    document.body.style.backgroundColor="red";
    }else{
    document.body.style.backgroundColor="orange";
    }
    }

    function getStyle(ele,attr){
    if(ele.window.getComputedStyle){
    return ele.window.getComputedStyle(ele,null)[attr];
    }else{
    return ele.currentStyle[attr];
    }
    }


  • 相关阅读:
    nginx系列11:负载均衡哈希算法ip_hash与hash模块
    nginx系列10:通过upstream模块选择上游服务器和负载均衡策略round-robin
    nginx系列9:HTTP反向代理请求处理流程
    css 滚动条样式
    Vue优化:常见会导致内存泄漏问题及优化
    vue自定义指令导致的内存泄漏问题解决
    vue动态绑定class的几种方式
    前端知识点回顾之重点篇——CSS中flex布局
    Javascript数组操作
    pc端常用电脑屏幕 ((响应式PC端媒体查询)电脑屏幕分辨率尺寸大全)
  • 原文地址:https://www.cnblogs.com/sunqq/p/7531229.html
Copyright © 2011-2022 走看看