前端练习1-月全食效果

此次月全食效果原理:
     用一组月全食的图片,让图片在x周上移动,从而做出月全食的效果。
<! 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=utf-8"  />
< title >  2011-06-16月全食 </ title  >
< style  type =  "text/css" >
     .moon  { background :  url("images/strip.jpg") 0 0px no-repeat ; height :  112px ; width :  112px ; overflow  : hidden ; display : block ;}
     .moon_scroll  {  height :  200px ;  width :  500px ; overflow  : auto ; display : none ;}
</ style >
</ head >
< body >
< div  class =  "moon"  id  = "moon" ></  div >
< div  class =  "moon_scroll"  id  = "moon_scroll"  >
< img  src =  "http://mat1.gtimg.com/hb/sucai/eclipse/spacer.jpg"  style ="  height :  1px ;  width :  1670px ;  display :  block ;"  />  <!--(13104 / 112) * 10 + 500-->
</ div >
< div  id =  "scrollLeft" ></ div  >
< script  type =  "text/javascript" >
( function (){
     var  w = 13104;  /*照片总长度*/
    var  step = parseInt(w / 112,10); /*小图片总数*/
     var  method =  new  Object();
    method.index = 0;
    method.running =  function (){
         if  (method.index >= step) {document.getElementById( 'moon_scroll'  ).style.display =  'block' ; return ;} /*如果当前走过的照片数大于等于总照片数,则显示为块级元素*/
        document.getElementById( 'moon'  ).style.backgroundPosition =  '-'  + (112 * method.index) +  'px 0' ;
        method.index++;
        setTimeout(method.running,100);  /*每个100毫秒运行一次method.running*/
    }
    
    method.running();
})();
( function (){
    document.getElementById(  'moon_scroll' ).onscroll =  function  () {
         var  left = Math.round(( this .scrollLeft) / 10);
        left = Math.min(13104/112-1,left);left = Math.max(0,left);
        document.getElementById( 'moon'  ).style.backgroundPosition =  '-'  + left*112 +  'px 0  '
        document.getElementById(  'scrollLeft' ).innerHTML = left;
    }
})();
</ script >
</ body >
</ html >
   
运行结果:
 (1)运行过程中:
   
 (2)运行结束后:
  
当点击左右的箭头时,滚动条会随之滑动,并且图片也会随之移动。
其中,图片strip.jpg为:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值