js实现百度动态LOGO

百度动态logo是通过循环改变div背景图片的位置,以达到动态的效果。

<!DOCTYPE html> 
<html lang="zh"> 
<head> 
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> 
<title>LOGO</title> 
<style type="text/css"> 
#banner { 
background: #52CCCC; 
cursor: move; 
} 
.content{
    height:100%;
}
html, body{
    height: 100%;
    width: 100%;
    margin: 0px;
    padding: 0px;
}
div.moveBar { width:400px; height:300px; position:absolute; left:50%; top:50%; margin-left:-200px; margin-top:-150px; background:#f90;}
</style> 
</head> 
<body style="padding-top: 50px;"> 

<div id="logo"  style="position: absolute; top: 0px; left: 50%; cursor: pointer; width: 270px; height: 129px; margin-left: -135px; background: url(logo_a5c3c8332558f4e2afafe351c4611716.png) -0px 0px no-repeat;" title="花灯流转赏元宵"></div>
<script> 
window.setInterval("changeBackground()",100);
var IMAGE_WIDTH = 16470,//图片的宽度
    PER_WIDTH = 270,//每一帧的宽度
    MIN_WIDTH = -(IMAGE_WIDTH - 2 * PER_WIDTH);
    function changeBackground(){
         var logo = document.getElementById('logo'),
            backgroundPosition,
            left;
        backgroundPosition = logo.style.backgroundPosition;
        left = parseInt(backgroundPosition.split(' ')[0]);

        left = (left > MIN_WIDTH) ? (left - PER_WIDTH) : 0;

        logo.style.backgroundPosition = left + 'px 0px';
    }
</script> 
</body> 
</html> 

其中logo_a5c3c8332558f4e2afafe351c4611716.png 是对应背景图片。
例:2016年2月22日元宵节

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值