新年賀卡制作

根據慕課網上視頻,寫的。


img
img

記錄一下:
html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1"/>
    <meta name="viewport" content="width=device-width,initial-scale=1.0, 
    minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="format-detection" content="telephone=no"/>
    <title>慕課賀春</title>
    
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <script type="text/javascript" src="js/main.js"></script>
</head>
<body>
    <div class="music">
        <img src="img/music_pointer.png">
        <img id="music" class="play" src="img/music_disc.png">
    </div>
    <div class="page" id="page1">
        <div class="bg"></div>
        <div class="p1_lantern">點擊屏幕<br />開啟好運2016</div>
        <div class="p1_immoc"></div>
        <div class="p1_words">2016年慕課網新年特獻</div>
    </div>
    <div class="page" id="page2">
        <div class="p2_bg_loading"></div>
        <div class="bg"></div>
        <div class="p2_circle"></div>
        <div class="p2_2016"></div>
    </div>
    <div class="page" id="page3">
        <div class="bg"></div>
        <div class="p3_logo"></div>
        <div class="p3_title"></div>
        <div class="p3_second"></div>
        <div class="p3_first"></div>
        <div class="p3_blessing"></div>
    </div>
    
    <audio autoplay="true">
    <source src="http://www.imooc.com/activity/project/project1/audio/happynewyear.mp3" type="audio/mpeg">
    
    </audio>
</body>
</html>

css:

/* all tag */

* {
    margin: 0;
    padding: 0;
    border: none;
    font-size: 1.5625vw;
    font-family: "microsoft yahei";
}

html,
body {
    height: 100%;
    overflow: hidden;
}


/**
 * music tag
 */

.music {
    width: 15vw;
    height: 15vw;
    border: 4px solid #ef1639;
    position: fixed;
    top: 3vh;
    right: 4vw;
    z-index: 5;
    border-radius: 50%;
    background: #fff;
}

.music > img:first-of-type {
    position: absolute;
    top: 24%;
    right: 2.5%;
    width: 28.421%;
    z-index: 1;
}

.music > img:last-of-type {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    margin: auto;
    width: 79%;
    z-index: 0;
}

.music > img.play {
    -webkit-animation: music_disc 4s linear infinite;
    -moz-animation: music_disc 4s linear infinite;
    -ms-animation: music_disc 4s linear infinite;
    -o-animation: music_disc 4s linear infinite;
    animation: music_disc 4s linear infinite;
}

@-webkit-keyframes music_disc {
    0% {
        -webkit-transform: rotate(0deg);
        -moz-transform: rotate(0deg);
        transform: rotate(0deg);
    }
    100% {
        -webkit-transform: rotate(360deg);
        -moz-transform: rotate(360deg);
        transform: rotate(360deg);
    }
}

@keyframes music_disc {
    0% {
        -webkit-transform: rotate(0deg);
        -moz-transform: rotate(0deg);
        transform: rotate(0deg);
    }
    100% {
        -webkit-transform: rotate(360deg);
        -moz-transform: rotate(360deg);
        transform: rotate(360deg);
    }
}


/**
 * page tag
 */

.page {
    position: absolute;
    width: 100%;
    height: 100%;
}

.page > .bg {
    position: absolute;
    z-index: -1;
    height: 100%;
    width: 100%;
}


/**
 * page1 tag
 */

#page1 {
    display: block;
}

#page1 > .bg {
    background: url(../img/p1_bg.jpg) no-repeat center center;
    background-size: 100%;
}

#page1 > .p1_lantern {
    position: absolute;
    top: -3.4%;
    right: 0;
    left: 0;
    margin: auto;
    background: url(../img/p1_lantern.png) no-repeat center bottom;
    background-size: 100%;
    width: 45vw;
    height: 71.2vh;
    font-size: 3.506rem;
    color: #fff;
    padding-top: 31vh;
    text-align: center;
    
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    -ms-box-sizing: border-box;
    -o-box-sizing: border-box;
    box-sizing: border-box;
}

#page1 > .p1_lantern:before {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: -1;
    content: "";
    margin: auto;
    width: 30vw;
    height: 30vw;
    background: #D60B3B;
    opacity: .5;
    border-radius: 50%;
    -webkit-box-shadow: 0 0 10vw 10vw #D60B3B;
    -moz-box-shadow: 0 0 10vw 10vw #D60B3B;
    -ms-box-shadow: 0 0 10vw 10vw #D60B3B;
    -o-box-shadow: 0 0 10vw 10vw #D60B3B;
    box-shadow: 0 0 10vw 10vw #D60B3B;
    -webkit-animation: p1_lantern .5s infinite alternate;
    -moz-animation: p1_lantern .5s infinite alternate;
    -o-animation: p1_lantern .5s infinite alternate;
    animation: p1_lantern .5s infinite alternate;
}

@-webkit-keyframes p1_lantern {
    0% {
        opacity: .5;
        -webkit-transform: scale(.8, .8);
        transform: scale(.8, .8);
    }
    100% {
        opacity: 1;
    }
}

@keyframes p1_lantern {
    0% {
        opacity: .5;
        -webkit-transform: scale(.8, .8);
        transform: scale(.8, .8);
    }
    100% {
        opacity: 1;
    }
}

#page1 > .p1_immoc {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    background: url(../img/p1_imooc.png) no-repeat center center;
    background-size: 100%;
    width: 27.656vw;
    height: 30.656vh;
    margin: auto;
}

#page1 > .p1_words {
    font-size: 2.314rem;
    position: absolute;
    right: 0;
    left: 0;
    bottom: 23px;
    text-align: center;
    color: #231815;
}


/**
 * page2 tag
 */

#page2 {
    display: none;
    -webkit-transition: .5s;
        transition: .5s;
}

#page2.fadeOut{
    opacity: .3;
    -webkit-transform: translate(0, -100%);
        transform: translate(0, -100%);
}

#page2 > .p2_bg_loading{
    z-index: 4;
    background: #ef1639;
    -webkit-animation: p2_bg_loading 1s linear forwards;
        animation: p2_bg_loading 1s linear forwards;
}

@-webkit-keyframes p2_bg_loading{
    from{
        opacity: 1;
    }
    to{
        opacity: 0;
    }
}

@keyframes p2_bg_loading{
    from{
        opacity: 1;
    }
    to{
        opacity: 0;
    }
}

#page2 > .bg {
    background: url(../img/p2_bg.jpg) no-repeat center center;
    background-size: 100%;
}

#page2 > .p2_circle {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    border-radius: 50%;
    background: url(../img/p2_circle_outer.png) no-repeat center center;
    background-size: 100%;
    width: 59.375vw;
    height: 59.375vw;
    -webkit-animation: p2_circle_outter 1s linear 3s infinite;
    animation: p2_circle_outter 1s linear 3s infinite;
}

@-webkit-keyframes p2_circle_outter {
    from {
        -webkit-transform: rotate(0deg);
        transform: rotate(0deg);
    }
    to {
        -webkit-transform: rotate(-360deg);
        transform: rotate(-360deg);
    }
}

@keyframes p2_circle_outter {
    from {
        -webkit-transform: rotate(0deg);
        transform: rotate(0deg);
    }
    to {
        -webkit-transform: rotate(-360deg);
        transform: rotate(-360deg);
    }
}

#page2 > .p2_circle:before {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    border-radius: 50%;
    content: "";
    background: url(../img/p2_circle_middle.png) no-repeat center center;
    background-size: 100%;
    width: 45.625vw;
    height: 45.625vw;
    -webkit-animation: p2_circle_middle 1s linear 2s infinite;
    animation: p2_circle_middle 1s linear 2s infinite;
}

@-webkit-keyframes p2_circle_middle {
    from {
        -webkit-transform: rotate(0deg);
        transform: rotate(0deg);
    }
    to {
        -webkit-transform: rotate(720deg);
        transform: rotate(720deg);
    }
}

@keyframes p2_circle_middle {
    from {
        -webkit-transform: rotate(0deg);
        transform: rotate(0deg);
    }
    to {
        -webkit-transform: rotate(720deg);
        transform: rotate(720deg);
    }
}

#page2 > .p2_circle:after {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    border-radius: 50%;
    content: "";
    background: url(../img/p2_circle_inner.png) no-repeat center center;
    background-size: 100%;
    width: 39.9375vw;
    height: 39.9375vw;
    -webkit-animation: p2_circle_inner 1s linear 1s infinite;
    animation: p2_circle_inner 1s linear 1s infinite;
}

@-webkit-keyframes p2_circle_inner {
    from {
        -webkit-transform: rotate(0deg);
        transform: rotate(0deg);
    }
    to {
        -webkit-transform: rotate(-1080deg);
        transform: rotate(-1080deg);
    }
}

@keyframes p2_circle_inner {
    from {
        -webkit-transform: rotate(0deg);
        transform: rotate(0deg);
    }
    to {
        -webkit-transform: rotate(-1080deg);
        transform: rotate(-1080deg);
    }
}

#page2 > .p2_2016 {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    background: url(../img/p2_2016.png) no-repeat center center;
    background-size: 100%;
    width: 27.5vw;
    height: 6.24vh;
}


/**
 * page3 tag
 */

#page3 {
    display: none;
    -webkit-transition: .5s;
        transition: .5s;
}

#page3.fadeIn{
    -webkit-transform: translate(0, -100%);
        transform: translate(0, -100%);
}

#page3 > .bg {
    background: url(../img/p3_bg.jpg) no-repeat center center;
    background-size: 100%;
}

#page3 > .p3_logo {
    width: 34.6875vw;
    height: 6.327vh;
    position: absolute;
    top: 7.82vh;
    right: 0;
    left: 0;
    margin: auto;
    background: url(../img/p3_logo.png) no-repeat center center;
    background-size: 100%;
}

#page3 > .p3_title {
    width: 48.125vw;
    height: 50vh;
    position: absolute;
    top: 21vh;
    right: 0;
    left: 0;
    margin: auto;
    background: url(../img/p3_title.png) no-repeat center center;
    background-size: 100%;
}

#page3 > .p3_second {
    width: 22.8125vw;
    height: 41.652vh;
    position: absolute;
    top: 25.48vh;
    left: 3.75vw;
    background: url(../img/p3_couplet_second.png) no-repeat center center;
    background-size: 100%;
}

#page3 > .p3_first {
    width: 22.8125vw;
    height: 41.652vh;
    position: absolute;
    top: 25.48vh;
    right: 3.75vw;
    background: url(../img/p3_couplet_first.png) no-repeat center center;
    background-size: 100%;
}

#page3 > .p3_blessing {
    width: 32vw;
    height: 32vh;
    position: absolute;
    right: 0;
    bottom: 3vh;
    left: 0;
    margin: auto;
    border-radius: 50%;
    background: url(../img/p3_blessing.png) no-repeat center center;
    background-size: 100%;
    -webkit-animation: p3_blessing 2s linear infinite;
    animation: p3_blessing 2s linear infinite;
}

@-webkit-keyframes p3_blessing {
    from {
        -webkit-transform: rotate(0deg);
        transform: rotate(0deg);
    }
    to {
        -webkit-transform: rotate(360deg);
        transform: rotate(360deg);
    }
}

@keyframes p3_blessing {
    from {
        -webkit-transform: rotate(0deg);
        transform: rotate(0deg);
    }
    to {
        -webkit-transform: rotate(360deg);
        transform: rotate(360deg);
    }
}

js


window.onload = function(){
    /*console.log("網頁可見區域寬:" + document.body.clientWidth);
    console.log("網頁可見區域高:" + document.body.clientHeight);
    console.log("網頁可見區域寬(包括邊線的寬):" + document.body.offsetWidth);
    console.log("網頁可見區域高(包括邊線的高):" + document.body.offsetHeight);
    console.log("網頁正文全文寬:" + document.body.scrollWidth);
    console.log("網頁正文全文高:" + document.body.scrollHeight);
    console.log("網頁被卷去的高:" + document.body.scrollTop);
    console.log("網頁被卷去的左:" + document.body.scrollLeft);
    console.log("網頁正文部分上:" + window.screenTop);
    console.log("網頁正文部分左:" + window.screenLeft);
    console.log("屏幕分辨率的寬:" + window.screen.width);
    console.log("屏幕分辨率的高:" + window.screen.height);
    console.log("屏幕可用工作區寬度:" + window.screen.availWidth);
    console.log("屏幕可用工作區高度:" + window.screen.availHeight);*/
    
    //獲取元素
    var page1 = document.getElementById("page1");
    var page2 = document.getElementById("page2");
    var page3 = document.getElementById("page3");
    
    var music = document.getElementById("music");
    var audio = document.getElementsByTagName("audio")[0];

    //當音樂播放完停止的時候,自動停止光盤旋轉效果
    audio.addEventListener("ended", function(event){
        music.setAttribute("class", "");
        //this.style.animationPlayState = "paused";
        //this.style.webkitAnimationPlayState = "paused";
    }, false);
    
    //點擊音樂圖標,控制音樂播放效果
    /*music.onclick = function(){
        if(audio.paused){
            audio.play();
            this.setAttribute("class","play");
            //this.style.animationPlayState = "running";
            //this.style.webkitAnimationPlayState = "running";
        }else{
            audio.pause();
            this.setAttribute("class","");
            //this.style.animationPlayState = "paused";
            //this.style.webkitAnimationPlayState = "paused";
        }
    }*/
    
    //點擊音樂圖標,控制音樂播放效果
    music.addEventListener("touchstart", function(event){
        if(audio.paused){
            audio.play();
            this.setAttribute("class","play");
            //this.style.animationPlayState = "running";
            //this.style.webkitAnimationPlayState = "running";
        }else{
            audio.pause();
            this.setAttribute("class","");
            //this.style.animationPlayState = "paused";
            //this.style.webkitAnimationPlayState = "paused";
        }
    }, false);
    
    //點擊屏幕,開啟好運2016
    page1.addEventListener("touchstart", function(event){
        page1.style.display = "none";
        page2.style.display = "block";
        page3.style.display = "block";
        page3.style.top = "100%";
        
        setTimeout(function(){
            page2.setAttribute("class", "page fadeOut");
            page3.setAttribute("class", "page fadeIn");
        }, 5500);
    }, false);
}

遇到的坑1,page3.style.top = "100%";寫成了 100% ,馬丹找了好久才發現問題的所在。
遇到的坑2,引入了js,在里面寫的點擊事件,但是就事沒有效果,經過排查,發現是上面被遮擋了,index-z 的問題。

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

推薦閱讀更多精彩內容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,775評論 25 708
  • 問答題47 /72 常見瀏覽器兼容性問題與解決方案? 參考答案 (1)瀏覽器兼容問題一:不同瀏覽器的標簽默認的外補...
    _Yfling閱讀 13,784評論 1 92
  • 圖片來源:pixabay.com 四年前,豆姐還未出生,我和豆媽便時常聊起將來她的教育問題。當時我們還沒有什么具體...
    王安迪閱讀 284評論 0 0
  • 當時生活的這一瞬間開始垂青你,如果你不回應,便是罪過。
    汐茗閱讀 241評論 0 1
  • 又快到年關,工資已花光。 摸摸空荷包,晚上沒吃飯。 剩蛋,剩蛋,忍痛分你一半。
    凱陵閱讀 661評論 0 0