模仿360开机效果

效果图:

原图片:

 

代码:

<!DOCTYPE html>
<html>
<head>
	<title>360开机效果</title>
	<style type="text/css">
		.box{
            width: 322px;
            position: fixed;
            bottom:0;
            right:0;
        }
        span{
            position: absolute;
            top:0;
            right:0;
            width:30px;
            height: 20px;
            cursor: pointer;
        }
	</style>
</head>
<body>
<div class="box" id="box">
    <span></span>
    <div class="hd" id="t">
        <img src="images/t.jpg" alt=""/>
    </div>
    <div class="bd" id="b">
        <img src="images/b.jpg" alt=""/>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
	var b = document.getElementById('b');
    var closeAd = document.getElementsByTagName("span")[0];

    closeAd.onclick = function(){
    	animate(b, {height : 0}, function(){
    		animate(b.parentNode, {width : 0})
    	})
    }

    function animate(obj, json, fn) {
    	clearInterval(obj.timer);
    	obj.timer = setInterval(function(){
    		var flag = true;
    		for(var attr in json) {
    			var current = parseInt(getStyle(obj, attr));
    			var step = (json[attr] - current) / 10;
    			step = step > 0 ? Math.ceil(step) : Math.floor(step);
    			obj.style[attr] = current + step + "px";
    			if (current != json[attr]) {
    				flag = false;
    			}
    		}

    		if (flag) {
    			clearInterval(obj.timer);
    			fn();
    		}

    	}, 30);
    }



   //获取样式属性值
    function getStyle(obj, attr){
		if (obj.currentStyle) {
			// IE浏览器识别
			return obj.currentStyle[attr];
		} else {
			return window.getComputedStyle(obj, null)[attr];
		}
	}
</script>

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值