运用CSS切换图片

HTML:

<!DOCTYPE HTML>
<htmllang="en-US">
    <head>
        <meta charset="UTF-8">
        <title>CSS3 Full Background Slider </title>
 <link rel="stylesheet" type="text/css" href="css/changePic.css">
    </head>
    <body>
        <div class="slider">
            <ul class="clearfix">
                <li><a href="#bg1">Hipster Fashion Haircut </a></li>
                <li><a href="#bg2">Cloud Computing Services & Consulting</a></li>
                <li><a href="#bg3">My haire is sooo fantastic!</a></li>
                <li><a href="#bg4">Eat healthy & excersice!</a></li>
                <li><a href="#bg5">Lips so kissable I could die ...</a></li>
            </ul>
        </div>
        ![](http://upload-images.jianshu.io/upload_images/2418875-4192f842e9da3a53.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
        ![](http://upload-images.jianshu.io/upload_images/2418875-813598a32bd4af2e.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
        ![](http://upload-images.jianshu.io/upload_images/2418875-cc54a99e20a6db7d.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
        ![](http://upload-images.jianshu.io/upload_images/2418875-f0864ed6c25e7921.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
        ![](http://upload-images.jianshu.io/upload_images/2418875-19799c798ff7d279.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
    </body>
</html>

CSS:

@importurl("http://www.w3cplus.com/demo/css3/base.css");
@importurl("http://fonts.googleapis.com/css?family=Yesteryear");

html,body{
    height: 100%;
}

img.bg {
    position: fixed;
    top: 0;
    /*   left: 50%; */
    min-height: 100%;
    min-width: 1024px;
    height: auto !important;
    width: 100%;
      z-index:1;
     /* -webkit-transform: translateX(-50%);
           -moz-transform: translateX(-50%);
             -o-transform: translateX(-50%);
           -ms-transform: translateX(-50%);
                  transform: translateX(-50%); */  /* 向左偏移50% */
}

.slider {
    position: absolute;
    bottom: 100px;
    width: 100%;
    z-index: 9999;
    text-align: center;
}

.slider li{
    display: inline-block;
      width: 170px;
      height: 130px;
      margin-right: 15px;
}

.slider a {
          display: inline-block;
            width: 170px;
            padding-top: 70px;
            padding-bottom: 20px;
            position: relative;
            cursor: pointer; /*指定鼠标指针为小手*/
            border: 2px solid #fff;
            border-radius: 5px;
            vertical-align: top;/*垂直对齐*/
            color: #fff;
            text-decoration: none;/*去除下划线*/
            font-size: 22px;
            font-family: 'Yesteryear', cursive;
            text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.8),-2px -2px 1px rgba(0, 0, 0, 0.3),-3px -3px 1px rgba(0, 0, 0, 0.3);
}

/*设置背景图片从左向右移入显示的动画效果*/
/* Slide Left */
            @-webkit-keyframes 'slideLeft' {
                0% { left: -500px; }
                100% { left: 0; }
            }
            @-moz-keyframes 'slideLeft' {
                0% { left: -500px; }
                100% { left: 0; }
            }
            @-o-keyframes 'slideLeft' {
                0% { left: -500px; }
                100% { left: 0; }
            }
            @-ms-keyframes 'slideLeft' {
                0% { left: -500px; }
                100% { left: 0; }
            }
            @keyframes 'slideLeft' {
                0% { left: -500px; }
                100% { left: 0; }
            }
            /*设置背景图像从底部向顶部移入的动画效果*/
             /* Slide Bottom */
            
            @-webkit-keyframes 'slideBottom' {
                0% { top: 350px; }
                100% { top: 0; }
            }
            @-moz-keyframes 'slideBottom' {
                0% { top: 350px; }
                100% { top: 0; }
            }
            @-ms-keyframes 'slideBottom' {
                0% { top: 350px; }
                100% { top: 0; }
            }
            @-o-keyframes 'slideBottom' {
                0% { top: 350px; }
                100% { top: 0; }
            }
            @keyframes 'slideBottom' {
                0% { top: 350px; }
                100% { top: 0; }
            }
            /*设置背景图片由小到大放大动画效果*/
            /* Zoom In */
            
            @-webkit-keyframes 'zoomIn' {
                0% { -webkit-transform: scale(0.1); }
                100% { -webkit-transform: none; }
            }
            @-moz-keyframes 'zoomIn' {
                0% { -moz-transform: scale(0.1); }
                100% { -moz-transform: none; }
            }
            @-ms-keyframes 'zoomIn' {
                0% { -ms-transform: scale(0.1); }
                100% { -ms-transform: none; }
            }
            @-o-keyframes 'zoomIn' {
                0% { -o-transform: scale(0.1); }
                100% { -o-transform: none; }
            }
            @keyframes 'zoomIn' {
                0% { transform: scale(0.1); }
                100% { transform: none; }
            }
            /*设置背景图像由大到小缩小动画效果*/
            /* Zoom Out */
            
            @-webkit-keyframes 'zoomOut' {
                0% { -webkit-transform: scale(2); }
                100% { -webkit-transform: none; }
            }
            @-moz-keyframes 'zoomOut' {
                0% { -moz-transform: scale(2); }
                100% { -moz-transform: none; }
            }
            @-ms-keyframes 'zoomOut' {
                0% { -ms-transform: scale(2); }
                100% { -ms-transform: none; }
            }
            @-o-keyframes 'zoomOut' {
                0% { -o-transform: scale(2); }
                100% { -o-transform: none; }
            }
            @keyframes 'zoomOut' {
                0% { transform: scale(2); }
                100% { transform: none; }
            }
            /*背景图像旋转出现动画效果*/
            /* Rotate */
            
            @-webkit-keyframes 'rotate' {
                0% { -webkit-transform: rotate(-360deg) scale(0.1); }
                100% { -webkit-transform: none; }
            }
            @-moz-keyframes 'rotate' {
                0% { -moz-transform: rotate(-360deg) scale(0.1); }
                100% { -moz-transform: none; }
            }
            @-ms-keyframes 'rotate' {
                0% { -ms-transform: rotate(-360deg) scale(0.1); }
                100% { -ms-transform: none; }
            }
            @-o-keyframes 'rotate' {
                0% { -o-transform: rotate(-360deg) scale(0.1); }
                100% { -o-transform: none; }
            }
            @keyframes 'rotate' {
                0% { transform: rotate(-360deg) scale(0.1); }
                100% { transform: none; }
            }
            /*设置背景图像不显示动画效果*/
            @-webkit-keyframes 'notTarget' {
                0% { z-index: 75; }
                100% { z-index: 75; }
            }
            @-moz-keyframes 'notTarget' {
                0% { z-index: 75; }
                100% { z-index: 75; }
            }
            @-ms-keyframes 'notTarget' {
                0% { z-index: 75; }
                100% { z-index: 75; }
            }
            @-o-keyframes 'notTarget' {
                0% { z-index: 75; }
                100% { z-index: 75; }
            }
            @keyframes 'notTarget' {
                0% { z-index: 75; }
                100% { z-index: 75; }
            }

/*设置不同列表的背景色*/
.slider li:nth-of-type(1)  a{
      background-color: #02646e;
      }
.slider li:nth-of-type(2) a{
      background-color: #eb0837;
      }
.slider li:nth-of-type(3) a{
      background-color: #67b374;
      }    
.slider li:nth-of-type(4) a{
      background-color: #e6674a;
      }    
.slider li:nth-of-type(5) a{
      background-color: #e61061;
      }

/*设置缩略图形状*/
a::after{
    position: absolute;
    top: -80px;
    left: 50%;
    content: "";
    display: block;
    height: 120px;
    width: 120px;
    border-radius: 50%;
    border: 5px solid #fff;
      margin-left: -60px;
      z-index: 9999;
    }
/*设置缩略图背景图像*/
.slider li:nth-of-type(1) a::after{
    background: url(http://www.w3cplus.com/demo/css3/CSS3Fullbackground/sbg1.jpg) no-repeat center;
}
.slider li:nth-of-type(2) a::after{
      background: url(http://www.w3cplus.com/demo/css3/CSS3Fullbackground/sbg2.jpg) no-repeat center;
      }
.slider li:nth-of-type(3) a::after{
      background: url(http://www.w3cplus.com/demo/css3/CSS3Fullbackground/sbg3.jpg) no-repeat center;
      }
.slider li:nth-of-type(4) a::after{
      background: url(http://www.w3cplus.com/demo/css3/CSS3Fullbackground/sbg4.jpg) no-repeat center;
      }
.slider li:nth-of-type(5) a::after{
      background: url(http://www.w3cplus.com/demo/css3/CSS3Fullbackground/sbg5.jpg) no-repeat center;
      }

/*给缩略图添加蒙板效果*/
 a::before{
    position: absolute;
    top: -80px;
      content:"";
      display: block;
      height: 120px;
      width: 120px;
      border: 5px solid #fff;
      border-radius: 50%;
      left: 50%;
      margin-left: -60px;
      z-index: 99999;
      background: rgba(0,0,0,0.3);
      }      

/*鼠标悬浮时,修改缩略图蒙板透明度*/
a:hover:before{
            opacity:0;
            }

/*背景图从左向右出现*/
.slideLeft:target{  
    z-index: 100;
    -webkit-animation-name: slideLeft;/*规定需要绑定到选择器的 keyframe 名称*/
    -webkit-animation-duration: 1s;/*规定完成动画所花费的时间,以秒或毫秒计。*/
    -webkit-animation-iteration-count: 1;/*规定动画应该播放的次数。*/
       -moz-animation-name: slideLeft;
       -moz-animation-duration: 1s;
       -moz-animation-iteration-count: 1;
         -ms-animation-name: slideLeft;
         -ms-animation-duration: 1s;
         -ms-animation-iteration-count: 1;
           -o-animation-name: slideLeft;
           -o-animation-duration: 1s;
           -o-animation-iteration-count: 1;
                animation-name: slideLeft;
                animation-duration: 1s;
                animation-iteration-count: 1;
}     

.slideBottom:target{
    z-index: 100;
    -webkit-animation-name: slideBottom;
    -webkit-animation-duration: 1s;
    -webkit-animation-iteration-count: 1;
    -moz-animation-name: slideBottom;
    -moz-animation-duration: 1s;
    -moz-animation-iteration-count: 1;
      -ms-animation-name: slideBottom;
      -ms-animation-duration: 1s;
      -ms-animation-iteration-count: 1;
        -o-animation-name: slideBottom;
        -o-animation-duration: 1s;
        -o-animation-iteration-count: 1;
               animation-name: slideBottom;
             animation-duration: 1s;
             animation-iteration-count: 1;
        }      
 .zoomIn:target{
        z-index: 100;
        -webkit-animation-name: zoomIn;
        -webkit-animation-duration: 1s;
        -webkit-animation-iteration-count: 1;
        -moz-animation-name: zoomIn;
        -moz-animation-duration: 1s;
        -moz-animation-iteration-count: 1;
        -ms-animation-name: zoomIn;
        -ms-animation-duration: 1s;
        -ms-animation-iteration-count: 1;
        -o-animation-name: zoomIn;
          -o-animation-duration: 1s;
        -o-animation-iteration-count: 1;
               animation-name: zoomIn;
             animation-duration: 1s;
             animation-iteration-count: 1;
    }
            
            /*背景图由大到小出现*/
.zoomOut:target{
    z-index: 100;
    -webkit-animation-name: zoomOut;
    -webkit-animation-duration: 1s;
    -webkit-animation-iteration-count: 1;
    -moz-animation-name: zoomOut;
    -moz-animation-duration: 1s;
    -moz-animation-iteration-count: 1;
    -ms-animation-name: zoomOut;
    -ms-animation-duration: 1s;
    -ms-animation-iteration-count: 1;
    -o-animation-name: zoomOut;
    -o-animation-duration: 1s;
    -o-animation-iteration-count: 1;
    animation-name: zoomOut;
    animation-duration: 1s;
    animation-iteration-count: 1;
}
            
/*背景图旋转出现*/
.rotate:target{
    z-index: 100;
    -webkit-animation-name: rotate;
    -webkit-animation-duration: 1s;
    -webkit-animation-iteration-count: 1;
    -moz-animation-name: rotate;
    -moz-animation-duration: 1s;
    -moz-animation-iteration-count: 1;
    -ms-animation-name: rotate;
    -ms-animation-duration: 1s;
    -ms-animation-iteration-count: 1;
    -o-animation-name: rotate;
    -o-animation-duration: 1s;
    -o-animation-iteration-count: 1;
    animation-name: rotate;
    animation-duration: 1s;
    animation-iteration-count: 1;
}

.bg:not(:target){
    -webkit-animation-name: notTarget;
    -webkit-animation-duration: 1s;
    -webkit-animation-iteration-count: 1;
    -moz-animation-name: notTarget;
    -moz-animation-duration: 1s;
    -moz-animation-iteration-count: 1;
    -ms-animation-name: notTarget;
    -ms-animation-duration: 1s;
    -ms-animation-iteration-count: 1;
    -o-animation-name: notTarget;
    -o-animation-duration: 1s;
    -o-animation-iteration-count: 1;
    animation-name: notTarget;
    animation-duration: 1s;
    animation-iteration-count: 1;
}

特别鸣谢 imooc

感谢查看
奉上福利一枚
http://note.youdao.com/noteshare?id=a2558c7afd02fa55ff9814fd429c8884&sub=69B8AAF714104B5DA168E9D17B53C682

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 13,816评论 1 92
  • 一、样式篇 第1章 初识jQuery (1)环境搭建 进入官方网站获取最新的版本 http://jquery.co...
    凛0_0阅读 3,467评论 0 44
  • 本课来自http://www.imooc.com/learn/9请不要用作商业用途。 HTML5 HTML介绍 H...
    PYLON阅读 3,326评论 0 5
  • 亲爱的你,现在我们已经不再联系,我们做过告别了啊。 亲爱的你,虽然我们做过告别了,可是我还是会想起你啊。 亲爱的你...
    灼雪阅读 138评论 0 0
  • 此段情,过去了吗? 文/小雪 有人问我:“你们的爱情真的结束了吗?” 我默默无语,摇了摇头。 20年走来,我经历过...
    半床诗阅读 283评论 0 2