仿一淘-气球背景效果



 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript" src="jquery-1.8.3.js"></script>
<style>
*{
  margin:0;
  padding:0;
}
body{
  text-align:center;
}
#out_div{
  margin:0 auto;
}
.divI{
  height:1500px;
  width:auto;
  position:relative;
}
.left{
  width:128px;
  border-right:1px solid #999;
  position:relative;
  top:100px;
  height:1400px;
  float:left;
}
.div1{
  background-color:#FFFFCC;
}
.div2{
  background-color:#9999FF;
}
.div3{
  background-color:#FFCCFF;
}
.div4{
  background-color:#CCCCFF;
}
.div5{
  background-color:#CC99FF;
}
.ball{
  top:-1px;
  left:50px;
  position:absolute;
  width:165px;
  height:230px;
}
.ball1{
  background:url(ball1.png) no-repeat 0 0;
  background-color: #960;
}
.ball2{
  background:url(ball1.png) no-repeat -222px 0;
  background-color:#036;
}
.ball3{
  background:url(ball1.png) no-repeat -446px 0;
  background-color:#093;
}
.ball4{
  background:url(ball1.png) no-repeat -670px 0;
  background-color:#F60;
}
.ball5{
  background:url(ball1.png) no-repeat -892px 0;
  background-color:#60C;
}
.divII{
  width:70%;
  height:1400px;
  border:1px solid blue;
  float:left;
  margin-left:10%;
  margin-top:50px;
}
</style>
</head>

<body>
<div id="out_div">
  <div class="divI div1">
     <div class="left">
     <div class="ball ball1"></div>
  </div>
  <div class="divII">
     内容
  </div>
  </div>
  <div class="divI div2">
     <div class="left">
        <div class="ball ball2">
  </div>
  </div>
  <div class="divII">
     内容
  </div>
  </div>
  <div class="divI div3">
     <div class="left">
        <div class="ball ball3"></div>
     </div>
  <div class="divII">
     内容
  </div>
  </div>
  <div class="divI div4">
     <div class="left">
        <div class="ball ball4"></div>
     </div>
  <div class="divII">
     内容
  </div>
  </div>
  <div class="divI div5">
     <div class="left">
        <div class="ball ball5"></div>
  </div>
  <div class="divII">
     内容
  </div>
  </div>
</div>
<script>
/*
*  仿一淘-根据scrollTop改变背景效果;
*  ie8,ff,opera测试可用,其他浏览器未测;
*  **********made by keimon*************
*  ***********2013-01-16**************
*/
$(window).scroll(function(){
   var t = $(document).scrollTop();
   var len = $('.divI').length;
   for(var i=0; i<len; i++){
      var num1 = i*1500+50; //1500是每个背景层的高度,可用根据自己的需求改变(css),
   var num2 = (i+1)*1500; //可以,用$('divI').height()来获得实际的页面高度;
   var j = i+1
   var b = '.ball'+j;
   if(t>num1 && t<num2){
      $(b).css('position','fixed');
   }else{
      $(b).css('position','absolute');
   }
   }
})
</script>
</body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值