首页 > 代码库 > 一排div自由下落

一排div自由下落

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(speed > target&& dir >0 || speed < target && dir < 0)        {            speed = target;        }        obj.style[attr] = speed + ‘px‘;        if(speed == target)        {            clearInterval(obj.timer);        }         endfn&&endfn();    },30)}*/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();    },50); };
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>无标题文档</title><script src="http://www.mamicode.com/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‘);        for( var i = 0; i < len; i++)    {        str += ‘<div style="width:50px; height:50px; background:red; position:absolute; top:0px; left:‘+ i*60 +‘px;"></div>‘;    }        document.body.innerHTML = str;        /*document.onclick = function ()    {        clearInterval(timer);        timer = setInterval( function ()        {            domove(adiv[num],‘top‘,23,500)            num++;            if( num == len )            {                clearInterval(timer);            }          },100)    };*/        document.onclick = function ()    {        clearInterval(timer);        timer = setInterval( function ()        {            domove(adiv[num],‘top‘,23,500)            num++;            if(len == num )            {                clearInterval(timer);            }        },100);    }};</script></head><body></body></html>

今天状态不佳(事实确实如此,其实都是借口 TAT)

看别人写了20分钟的代码 自己练了4遍以后 才能一口气准确无误的写出来 告诉我的智商怎么了 拿什么救你

然后说正经的

就是有些传参的时候参数的拼写大小写 一定要注意注意注意!!!!!!!!!!!

 

一排div自由下落