码迷,mamicode.com
首页 > 其他好文 > 详细

20150621百叶窗效果

时间:2015-06-21 11:46:06      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:

html==========

<ul id="ul">
        <li>
            <div>
                <p>111111</p>
                <p>222222</p>
            </div>
        </li>

        <li>
            <div>
                <p>333333</p>
                <p>444444</p>
            </div>
        </li>
        <li>
            <div>
                <p>555555</p>
                <p>666666</p>
            </div>
        </li>
        <li>
            <div>
                <p>777777</p>
                <p>888888</p>
            </div>
        </li>
    </ul>


css==============

#ul{width: 300px;height: 500px;border-top:1px solid #ccc;position: absolute;}
*{margin: 0;padding: 0;}
li{overflow: hidden;width: 300px;list-style:none;line-height: 30px;height: 30px;position: relative;;left: 0;top: 0;}
li div{position: absolute;top: 0px;left: 0;}


js==============



function css(obj, attr){
    if(obj.currentStyle){
        return obj.currentStyle[attr];
    } else {
        return getComputedStyle(obj, null)[attr];
    }
}
function move(obj,attr,target,fn){
    obj.timer && clearInterval(obj.timer);
    obj.timer = setInterval(function(){
        var cur = parseInt(css(obj, attr));
        var speed = (target - cur) / 8;
        var stop = true;
        speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
        if(target != cur){
            stop = false;
        }
        obj.style[attr] = speed + cur + ‘px‘;
        if(stop){
            clearInterval(obj.timer);
            obj.timer = null;
            fn && fn.call(obj);
        }
    }, 20);
}
var div=document.getElementsByTagName(‘div‘);
var timer=null;
var iNow=0;
var btn=true;
setInterval(function () {
    change();
},3000);
function change() {
    var timer=setInterval(function () {
        if(iNow==div.length){
            clearInterval(timer);
            iNow=0;
            btn=!btn;
        }else if(btn){
            move(div[iNow],‘top‘,-30)
            iNow++;
        }else{
            move(div[iNow],‘top‘,0);
            iNow++;
        }
    },100);
}

 

20150621百叶窗效果

标签:

原文地址:http://www.cnblogs.com/wz0107/p/4591715.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!