zoukankan      html  css  js  c++  java
  • 一排下去再上来的div

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    
    <script src="float.js"></script>
    <script type="text/javascript">
    window.onload = function ()
    {
        var timer = null ;
        var num = 0;
        var len = 20;
        var str = '';
        var adiv = document.getElementsByTagName('div');
        var finished = true;
        var flag = true;
        
        for( var i = 0; i < len; i++)
        {
            str += '<div style="50px; height:50px; background:red; position:absolute; top:0px; left:'+ i*60 +'px;"></div>';
        }
        
        document.body.innerHTML = str;
        
        
        document.onclick = function ()
        {
            
            if(!finished) {return ;}
            finished = false;
            clearInterval(timer);
            timer = setInterval( function ()
            {    
                domove(adiv[num],'top',23,flag?500:0,num == len - 1?function (){ finished = true;flag = !flag; }:null);
                num++;
                if(len == num )
                {
                    clearInterval(timer);
                    num = 0;
                }
            },100);
        }
    };
    </script>
    
    </head>
    
    <body>
    </body>
    </html>
    function getstyle(obj,attr)
    {
        return obj.currentStyle?obj.currentStyle[attr]:getComputedStyle(obj)[attr];
    }
    
    
    function domove (obj,attr,dir,target,endfn)
    {
        dir = parseInt(getstyle(obj,attr))<target?dir:-dir;
        clearInterval(obj.timer);
        obj.timer = setInterval( function ()
        {
            var speed = parseInt(getstyle(obj,attr)) + dir;
            if(dir>0&&speed>target||dir<0&&speed<target)
            {
                speed = target;
            }
            obj.style[attr] = speed + 'px';
            if( speed == target )
            {
                clearInterval(obj.timer);
                endfn&&endfn();
            }
        },30); 
    };
  • 相关阅读:
    vim删除以#,空格开头的行
    Element-ui 中对表单进行验证
    VUE页面实现加载外部HTML方法
    vue-cli2嵌入html
    文字环绕图片
    LocalDate计算两个日期相差天数
    springboot+vue脚手架使用nginx前后端分离
    通过 Netty、ZooKeeper 手撸一个 RPC 服务
    Spring Native 项目,把 Spring 项目编译成原生程序!
    印象笔记吐槽
  • 原文地址:https://www.cnblogs.com/mayufo/p/4179271.html
Copyright © 2011-2022 走看看