• 计数器


    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">

    <style>

    ul {
    100px;
    height: 50px;
    margin:40px auto;
    list-style: none;
    padding: 0;
    overflow: hidden;
    border:1px dashed green;
    position: relative;
    }
    li {
    100%;
    height: 100%;
    font-size: 50px;
    line-height: 50px;
    text-align: center;
    color:red;
    position: absolute;
    background-color: gray;
    transition-duration : 1s;
    transform: translateY(50px)
    }

    .prev {
    transform: translateY(-50px)
    }

    .curr {
    transform: translateY(0px);
    z-index : 9;
    }

    .next {
    transform: translateY(50px)
    }

    </style>
    <title>number</title>

    <script>

    /**
    * 计数器
    * @param {Element} eles [description]
    */
    function Animate(eles){
    var idx = 0;
    this.index = idx;
    this.eles = eles;
    this.max = eles.length-1;
    this.init();
    }

    /**
    * 初始状态
    * @return {[type]} [description]
    */
    Animate.prototype.init = function(){
    this.eles[0].className = 'curr';
    }

    Animate.prototype.start = function(){
    var i = this.index;
    var max = this.max

    if(this.index == 0){
    this.prev = null;
    this.curr = this.eles[i];
    this.next = this.eles[i+1];
    }else if(i == max){
    this.prev = this.eles[i-1];
    this.curr = this.eles[i];
    this.next = null;
    }else{
    this.prev = this.eles[i-1];
    this.curr = this.eles[i];
    this.next = this.eles[i+1];
    }

    this.doAnit();
    }

    /**
    * 循环计数
    * @return {[type]} [description]
    */
    Animate.prototype.doAnit = function(){
    if(!this.next){
    this.init();
    this.prev.removeAttribute('class');
    this.curr.className = 'prev';
    this.index = -1;
    }else if(!this.prev){
    this.curr.className = 'prev';
    this.next.className = 'curr';
    this.eles[this.max].removeAttribute('class')
    }else{
    this.prev.removeAttribute('class');
    this.curr.className = 'prev';
    this.next.className = 'curr';
    }
    this.index++;
    var that = this;
    var t = setTimeout(function(){
    clearTimeout(t)
    that.start();
    },1000)
    }

    /**************************************************/
    window.onload = function(){
    var noop = document.querySelector('#noop');

    document.onclick = function(){
    a.start();
    this.onclick = null;
    }

    var a = new Animate(noop.children);
    }

    </script>
    </head>
    <body>
    <ul id="noop">
    <li>0</li>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
    <li>7</li>
    <li>8</li>
    <li>9</li>
    </ul>
    </body>
    </html>

  • 相关阅读:
    swiper获取当前的index ( loop=true时,)
    解决ios浏览器页面滚动到底部或顶部后,页面局部滑动失效的问题
    js实现全屏与退出全屏
    Ueditor 关于视频上传相关问题
    git拉取单个子目录
    XShell上传文件到Linux服务器上
    Debian中安装MySQL服务器
    lamda表达式的由来
    工具类--验证码工具类
    工具类--线程相关工具类
  • 原文地址:https://www.cnblogs.com/lk516924/p/4111147.html
Copyright © 2020-2023  润新知