运用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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,440评论 5 467
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,814评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,427评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,710评论 1 270
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,625评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,014评论 1 275
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,511评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,162评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,311评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,262评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,278评论 1 328
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,989评论 3 316
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,583评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,664评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,904评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,274评论 2 345
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,856评论 2 339

推荐阅读更多精彩内容

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