運用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閱讀 230,182評論 6 543
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,489評論 3 429
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 178,290評論 0 383
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,776評論 1 317
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,510評論 6 412
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,866評論 1 328
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,860評論 3 447
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 43,036評論 0 290
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,585評論 1 336
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,331評論 3 358
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,536評論 1 374
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 39,058評論 5 363
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,754評論 3 349
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,154評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,469評論 1 295
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,273評論 3 399
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,505評論 2 379

推薦閱讀更多精彩內容

  • 問答題47 /72 常見瀏覽器兼容性問題與解決方案? 參考答案 (1)瀏覽器兼容問題一:不同瀏覽器的標簽默認的外補...
    _Yfling閱讀 13,781評論 1 92
  • 一、樣式篇 第1章 初識jQuery (1)環境搭建 進入官方網站獲取最新的版本 http://jquery.co...
    凜0_0閱讀 3,437評論 0 44
  • 本課來自http://www.imooc.com/learn/9請不要用作商業用途。 HTML5 HTML介紹 H...
    PYLON閱讀 3,291評論 0 5
  • 親愛的你,現在我們已經不再聯系,我們做過告別了啊。 親愛的你,雖然我們做過告別了,可是我還是會想起你啊。 親愛的你...
    灼雪閱讀 136評論 0 0
  • 此段情,過去了嗎? 文/小雪 有人問我:“你們的愛情真的結束了嗎?” 我默默無語,搖了搖頭。 20年走來,我經歷過...
    半床詩閱讀 271評論 0 2