Chinaunix首页 | 论坛 | 博客
  • 博客访问: 157379
  • 博文数量: 42
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 399
  • 用 户 组: 普通用户
  • 注册时间: 2015-09-23 11:47
个人简介

程序猿啊程序猿

文章分类

全部博文(42)

文章存档

2016年(28)

2015年(14)

我的朋友

分类: Html/Css

2016-07-06 16:07:51


点击(此处)折叠或打开

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <script src="jquery.js"></script>
  6.     <title>百叶窗轮播</title>
  7.     <style>
  8.       *{
  9.           padding:0;
  10.           margin:0;
  11.       }
  12.       .view{
  13.           position: relative;
  14.         width: 400px;
  15.         height: 300px;
  16.         left:200px;
  17.         top:100px;
  18.         overflow: hidden;
  19.       }
  20.       .carousel{
  21.           width: 400px;
  22.           height: 300px;
  23.           position: absolute;
  24.       }
  25.       .part1,.part2,.part3,.part4{
  26.           width: 100px;
  27.           height: 300px;
  28.           float: left;
  29.           position: relative;
  30.       }
  31.       .div{
  32.           background: url(images/1.jpg) no-repeat;
  33.       }
  34.       .div4 .part1{
  35.           background: url(images/1.jpg) no-repeat;
  36.           background-position:0%;
  37.       }
  38.       .div4 .part2{
  39.           background: url(images/1.jpg) no-repeat;
  40.           background-position: 33%;
  41.       }
  42.       .div4 .part3{
  43.         background: url(images/1.jpg) no-repeat;
  44.           background-position: 66%;
  45.       }
  46.       .div4 .part4{
  47.           background: url(images/1.jpg) no-repeat;
  48.           background-position:99%;
  49.       }
  50.       .div3 .part1{
  51.           background: url(images/4.jpg) no-repeat;
  52.           background-position:0%;
  53.       }
  54.       .div3 .part2{
  55.           background: url(images/4.jpg) no-repeat;
  56.           background-position:33%;
  57.       }
  58.       .div3 .part3{
  59.         background: url(images/4.jpg) no-repeat;
  60.           background-position:66%;
  61.       }
  62.       .div3 .part4{
  63.           background: url(images/4.jpg) no-repeat;
  64.           background-position:99%;
  65.       }
  66.      .div1 .part1,.div1 .part2,.div1 .part3,.div1 .part4,.div2 .part1,.div2 .part2,.div2 .part3,.div2 .part4{
  67.           width: 400px;
  68.           height: 75px;
  69.           position: relative;
  70.       }
  71.       .div1 .part1{
  72.           background: url(images/2.jpg) no-repeat;
  73.           background-position: 0 0;
  74.       }
  75.       .div1 .part2{
  76.           background: url(images/2.jpg) no-repeat;
  77.           background-position: 0 33%;
  78.       }
  79.       .div1 .part3{
  80.           background: url(images/2.jpg) no-repeat;
  81.           background-position: 0 66%;
  82.       }
  83.       .div1 .part4{
  84.           background: url(images/2.jpg) no-repeat;
  85.           background-position: 0 99%;
  86.       }

  87.       .div2 .part1{
  88.           background: url(images/3.jpg) no-repeat;
  89.           background-position: 0 0;
  90.       }
  91.       .div2 .part2{
  92.           background: url(images/3.jpg) no-repeat;
  93.           background-position: 0 33%;
  94.       }
  95.       .div2 .part3{
  96.           background: url(images/3.jpg) no-repeat;
  97.           background-position: 0 66%;
  98.       }
  99.       .div2 .part4{
  100.           background: url(images/3.jpg) no-repeat;
  101.           background-position: 0 99%;
  102.       }
  103.     </style>
  104. </head>
  105. <body>
  106.     <div class="view">
  107.         <div class="carousel div">
  108.             
  109.         </div>
  110.         <div class="carousel div1">
  111.             <div class="part1"></div>
  112.             <div class="part2"></div>
  113.             <div class="part3"></div>
  114.             <div class="part4"></div>    
  115.         </div>
  116.         <div class="carousel div2">
  117.             <div class="part1"></div>
  118.             <div class="part2"></div>
  119.             <div class="part3"></div>
  120.             <div class="part4"></div>    
  121.         </div>
  122.         <div class="carousel div3">
  123.             <div class="part1"></div>
  124.             <div class="part2"></div>
  125.             <div class="part3"></div>
  126.             <div class="part4"></div>            
  127.         </div>
  128.         <div class="carousel div4">
  129.             <div class="part1"></div>
  130.             <div class="part2"></div>
  131.             <div class="part3"></div>
  132.             <div class="part4"></div>
  133.         </div>
  134.     </div>
  135. <script>
  136.     //思路如下:
  137.     //一个大的div分成四个等份的小div,然后利用CSS的一个属性 background-position来把背景图片定位在小的div中
  138.     //把四个小的div拼成一个完成图片来实现图片的百叶窗效果
  139.     $(function(){
  140.         function div4M(){
  141.                 $(".div4 .part1").animate({
  142.          top:"300px"
  143.                 },1000,'linear',function(){
  144.                     $(".div4 .part2").animate({
  145.                         top:"300px"
  146.                     },1000,'linear',function(){
  147.                         $(".div4 .part3").animate({
  148.                             top:"300px"
  149.                         },1000,'linear',function(){
  150.                             $(".div4 .part4").animate({
  151.                                 top:"300px"
  152.                             },1000,'linear',function(){
  153.                                 $(".div4 .part1,.div4 .part2,.div4 .part3,.div4 .part4").css("top","0").hide();
  154.                                 $(".div3 .part1,.div3 .part2,.div3 .part3,.div3 .part4").css("top","0").show();
  155.                                 $(".div2 .part1,.div2 .part2,.div2 .part3,.div2 .part4").css("left","0").show();
  156.                                 div3M();
  157.                             })
  158.                         })
  159.                     })
  160.                 })    
  161.         }
  162.         function div3M(){
  163.                     $(".div3 .part4").animate({
  164.                  top:"300px"
  165.                         },1000,'linear',function(){
  166.                             $(".div3 .part3").animate({
  167.                                 top:"300px"
  168.                             },1000,'linear',function(){
  169.                                 $(".div3 .part2").animate({
  170.                                     top:"300px"
  171.                                 },1000,'linear',function(){
  172.                                     $(".div3 .part1").animate({
  173.                                         top:"300px"
  174.                                     },1000,'linear',function(){
  175.                                         $(".div3 .part1,.div3 .part2,.div3 .part3,.div3 .part4").css("top","0").hide();
  176.                                         $(".div2 .part1,.div2 .part2,.div2 .part3,.div2 .part4").css("left","0").show();
  177.                                         $(".div1 .part1,.div1 .part2,.div1 .part3,.div1 .part4").css("right","0").show();
  178.                                         div2M();
  179.                                  })
  180.                              })
  181.                          })
  182.                     })    
  183.         }
  184.         function div2M(){
  185.             $(".div2 .part4").animate({
  186.          left:"400px"
  187.                 },1000,'linear',function(){
  188.                     $(".div2 .part3").animate({
  189.                         left:"400px"
  190.                     },1000,'linear',function(){
  191.                         $(".div2 .part2").animate({
  192.                             left:"400px"
  193.                         },1000,'linear',function(){
  194.                             $(".div2 .part1").animate({
  195.                                 left:"400px"
  196.                             },1000,'linear',function(){
  197.                                 $(".div2 .part1,.div2 .part2,.div2 .part3,.div2 .part4").css("left","0").hide();
  198.                                 $(".div1 .part1,.div1 .part2,.div1 .part3,.div1 .part4").css("right","0").show();
  199.                                 div1M();
  200.                          })
  201.                      })
  202.                  })
  203.             })
  204.         }
  205.         function div1M(){
  206.             $(".div1 .part4").animate({
  207.          right:"400px"
  208.                 },1000,'linear',function(){
  209.                     $(".div1 .part3").animate({
  210.                         right:"400px"
  211.                     },1000,'linear',function(){
  212.                         $(".div1 .part2").animate({
  213.                             right:"400px"
  214.                         },1000,'linear',function(){
  215.                             $(".div1 .part1").animate({
  216.                                 right:"400px"
  217.                             },1000,'linear',function(){
  218.                                 $(".div1 .part1,.div1 .part2,.div1 .part3,.div1 .part4").css("right","0").hide();
  219.                                 $(".div4 .part1,.div4 .part2,.div4 .part3,.div4 .part4").css("top","0").show();
  220.                                 $(".div3 .part1,.div3 .part2,.div3 .part3,.div3 .part4").css("top","0").show();
  221.                                 div4M();
  222.                          })
  223.                      })
  224.                  })
  225.             })
  226.         }
  227.         div4M();
  228.     })
  229. </script>
  230. </body>
  231. </html>

阅读(2563) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~