国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

html動(dòng)態(tài)愛(ài)心代碼【四】(附源碼)

這篇具有很好參考價(jià)值的文章主要介紹了html動(dòng)態(tài)愛(ài)心代碼【四】(附源碼)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

目錄

前言

特效

完整代碼

?總結(jié)


前言

情人節(jié)馬上就要到了,為了幫助大家高效表白,下面再給大家?guī)?lái)了實(shí)用的HTML浪漫表白代碼(附源碼)+背景音樂(lè),可用于520,情人節(jié),生日,表白等場(chǎng)景,可直接使用。

特效

html動(dòng)態(tài)愛(ài)心代碼【四】(附源碼),愛(ài)心,html,前端,html5,css,javascript

完整代碼

?html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>心心-樣例圖</title>

<link href="favicon.ico" rel="shortcut icon" class="icon-love" type="images/x-ico">

<link rel="stylesheet" href="css/love.css">

</head>
<body>

<div class="container" onselectstart="return false;" unselectable="on" style="-moz-user-select:none;">

    <div class="body_left">
        <img src="images/biubiubiu.gif" alt="" ondragstart='return false;'>
    </div>

    <div class="body_center love">
        <div class="block">
            <div class="div1"></div>
            <div class="div2"></div>
            <div class="div3"></div>
            <div class="div4"></div>
        </div>
    </div>

</div>

<div class="footer">
    <div class="border">
        <div class="border-top"></div>
        <div class="border-bottom"></div>
    </div>

    
</div>

<script type="text/javascript" src="js/love.js"></script>

</body>
</html>

css

* {
    margin: 0;
    padding: 0;
    border: 0;
}
.icon-love {
    width: 400px;
}
html, body {
    width: 100%;
    height: 100%;
}

body {
    /*background-color: skyblue;*/
    overflow: hidden;   /*隱藏超出的部分*/
}

.container {
    width: 100%;
    height: 100%;
    position: relative;
}

/*---------------------- body_left -------------------------*/
.body_left {
    width: 300px;
    height: 300px;
    left: 0;
    bottom: 110px;
    position: absolute;
    z-index: 98;

}

/*---------------------- body_left -------------------------*/

/*---------------------- body_center -------------------------*/
.container .love {
    width: 520px; /* 13 * 40 */
    height: 440px; /* 11 * 40 */
    left: 50%;
    top: 50%;
    position: absolute;
    margin: -260px 0 0 -220px;
    /*background-color: gray;*/
}

.love .block {
    right: 0;
    position: absolute;
    visibility: hidden; /*未開(kāi)始升空動(dòng)畫前隱藏*/
    background-color: yellow;
}

.love .block div {
    width: 40px;
    height: 40px;
    position: absolute;
    background: url("../images/heart.png") no-repeat;
    background-size: contain;
    /*background-color: #c40908;*/
    /*border: 1px solid silver;*/
    box-sizing: border-box;
}


/*---------------------- body_center -------------------------*/

/*---------------------- footer -------------------------*/
@keyframes border {
    0% {
        width: 0;
    }
    5% {
        width: 5%;
    }
    10% {
        width: 10%;
    }
    15% {
        width: 15%;
    }
    20% {
        width: 20%;
    }
    25% {
        width: 25%;
    }
    30% {
        width: 30%;
    }
    35% {
        width: 35%;
    }
    40% {
        width: 40%;
    }
    45% {
        width: 45%;
    }
    50% {
        width: 50%;
    }
    55% {
        width: 55%;
    }
    60% {
        width: 60%;
    }
    65% {
        width: 65%;
    }
    70% {
        width: 70%;
    }
    75% {
        width: 75%;
    }
    80% {
        width: 80%;
    }
    85% {
        width: 85%;
    }
    90% {
        width: 90%;
    }
    95% {
        width: 95%;
    }
    100% {
        width: 100%;
    }

}
.footer {
    bottom: 30px;
    position: relative;
    z-index: 99;
}
.footer .border .border-top {
    /*width: 0;*/
    /*display: inline-block;*/
    border-top: 3px solid black;
    transform-origin: left center;
    -webkit-animation: border 312 linear;
    -o-animation: border 12s linear;
    animation: border 12s linear;
    animation-fill-mode : both;
    /*border-bottom: none;*/
}

.footer .border .border-bottom {
    /*width: 0;*/
    /*display: inline-block;*/
    float: right;
    border-top: 3px solid red;
    transform-origin: right center;
    -webkit-animation: border 7s linear 12s;
    -o-animation: border 7s linear 12s;
    animation: border 7s linear 12s;
    animation-fill-mode : both;
    /*border-bottom: none;*/
}

.footer .copyright {
    width: 100%;
    height: 30px;
    position: absolute;
    bottom: -30px;
    text-align: center;
    /*background-color: gray;*/

}

.copyright div {
    width: 30%;
    line-height: 30px;
    display: inline-block;
}

.copyright div span {
    color: dimgray;
}

/*---------------------- footer -------------------------*/

js

const blk_pitn = { //各小方塊相對(duì)【自身中心】的位置 -- 【自身中心】確定為#div22的方塊
        block1: [[0, 1], [0, 0], [-1, 0], [-1, -1]],
        block2: [[0, 1], [0, 0], [-1, 0], [0, -1]],
        block3: [[-1, 1], [0, 0], [-1, 0], [-1, -1]],
        block4: [[0, 1], [0, 0], [-1, 0], [-1, -1]], /* 1 */
        block5: [[-1, 1], [0, 0], [-1, 0], [0, -1]],
        block6: [[0, -1], [0, 0], [-1, 0], [1, -1]],
        block7: [[-1, -1], [0, 0], [-1, 0], [1, 0]],
        block8: [[-1, 1], [0, 0], [-1, 0], [-1, -1]], /* 3 */
        block9: [[0, -1], [0, 0], [-1, 0], [1, 0]],
        block10: [[-1, 1], [0, 0], [-1, 0], [1, 0]],
        block11: [[2, 0], [0, 0], [-1, 0], [1, 0]], /* — */
        block12: [[0, 1], [0, 0], [-1, 0], [0, -1]], /* 2 */
        block13: [[0, 1], [0, 0], [-1, 0], [-1, -1]], /* 1 */
        block14: [[1, 1], [0, 0], [-1, 0], [1, 0]],
        block15: [[1, -1], [0, 0], [-1, 0], [1, 0]],
        block16: [[-1, -1], [0, 0], [-1, 0], [1, 0]], /* 7 */
        block17: [[0, 1], [0, 0], [-1, 0], [0, -1]], /* 2 */
        block18: [[0, 1], [0, 0], [-1, 0], [-1, -1]], /* 1 */
        block19: [[0, -1], [0, 0], [-1, 0], [1, 0]], /* 9 */
        block20: [[1, -1], [0, 0], [-1, 0], [1, 0]],
        block21: [[0, 1], [0, 0], [-1, 0], [-1, -1]], /* 1 */
        block22: [[1, 1], [0, 0], [-1, 0], [1, 0]], /* 14 */
        block23: [[0, 2], [0, 0], [0, -1], [0, 1]]      /* | */
    },
    offset_pitn = { //各方塊block相對(duì)【愛(ài)心中心】的位置
        block1: [5, 3],
        block2: [5, 1],
        block3: [3, 4],
        block4: [3, 2],
        block5: [3, -1],
        block6: [2, 5],
        block7: [2, 1],
        block8: [1, -1],
        block9: [1, -3],
        block10: [1, 2],
        block11: [0, 3],
        block12: [0, 0], /* 【愛(ài)心中心】*/
        block13: [-1, -4],
        block14: [0, -2],
        block15: [-2, 4],
        block16: [-2, 2],
        block17: [-2, 0],
        block18: [-3, -2],
        block19: [-4, 0],
        block20: [-3, 5],
        block21: [-5, 3],
        block22: [-4, 1],
        block23: [-6, 1]    /* 因動(dòng)畫需要移動(dòng)一個(gè)方塊,故y軸坐標(biāo)-1*/
    };

let blocks = document.getElementsByClassName("block"),
    block = blocks[0],
    love = document.getElementsByClassName("love")[0],
    timer = null,
    index = 0,  //記錄拼接愛(ài)心的動(dòng)畫步驟
    clone_block;    //用于克隆方塊

//1.移動(dòng)方塊的【自身中心】到【愛(ài)心中心】
block.style.top = "50%";
block.style.left = "50%";
block.style.margin = "-20px 0 0 -20px";

const block_left = parseFloat(window.getComputedStyle(block, null).left.slice(0, -2)), //【愛(ài)心中心】 左邊距離父元素的距離
    block_top = parseFloat(window.getComputedStyle(block, null).top.slice(0, -2));  //【愛(ài)心中心】 頂部距離父元素的距離

function Next() {
    if (++index >= 24) {
        clearInterval(timer);

        Rise();
        // alert("已經(jīng)是最后一個(gè)了!");
        return;
    }

    block.style.visibility = "visible"; //升空動(dòng)畫前允許可見(jiàn)

    //2.移動(dòng)方塊到指定的位置-即是移動(dòng)【自身中心】到目標(biāo)位置
    block.style.left = block_left + 40 * offset_pitn["block" + index][0] + "px";
    block.style.top = block_top - 40 * offset_pitn["block" + index][1] + "px";
    for (let i = 0; i < block.children.length; i++) {
        // block.children[1].innerText = index;    //編號(hào)便于調(diào)試
        block.children[i].style.left = blk_pitn["block" + index][i][0] * -40 + "px";
        /* -40 是因?yàn)檫壿嬜鴺?biāo)和瀏覽器的x,y軸方向不一樣*/
        block.children[i].style.top = blk_pitn["block" + index][i][1] * -40 + "px";
    }

    //3.克隆方塊—保存現(xiàn)在的位置
    /* 一共會(huì)克隆23個(gè)方塊,加上原先的一個(gè)方塊block,共24個(gè)方塊,即多出原先的block方塊*/
    clone_block = block.cloneNode(true);
    love.appendChild(clone_block);

    if (love.children.length >= 24) {
        blocks[blocks.length - 1].children[2].style.display = "none"; //去掉多余的小方塊
        block.style.display = "none";   //隱藏多出的block方塊
    }
}

function Rise() {
    //4.愛(ài)心升高,多出的那個(gè)小方塊開(kāi)始掉落
    console.log("開(kāi)始升空");
    let timer2 = null,
        distance = 0;
    /* 升高時(shí),移動(dòng)的距離*/
    const target = 120, /* 目標(biāo)距離*/
        speed = 1;
    /*移動(dòng)速度*/

    let love_top = parseFloat(window.getComputedStyle(love, null).top.slice(0, -2));  //愛(ài)心盒子距離屏幕頂部的距離


    timer2 = setInterval(() => {
        distance += speed;
        // console.log(distance);
        if (distance >= target) {
            clearInterval(timer2);

            console.log("升空完畢");

        }

        love.style.top = (love_top - distance) + "px";

    }, 22);

}

window.onload = function () {
    setTimeout(() => {

        timer = setInterval(() => {
            Next();
        }, 300);


    }, 12000);   //gif圖播放完畢所需時(shí)間為11.73s
};

圖片

html動(dòng)態(tài)愛(ài)心代碼【四】(附源碼),愛(ài)心,html,前端,html5,css,javascript

html動(dòng)態(tài)愛(ài)心代碼【四】(附源碼),愛(ài)心,html,前端,html5,css,javascript

?總結(jié)

css與js代碼較多,便作了分離,大家導(dǎo)入html后,注意引入css和js

祝大家在情場(chǎng)順風(fēng)順?biāo)?/strong>

html動(dòng)態(tài)愛(ài)心代碼【四】(附源碼),愛(ài)心,html,前端,html5,css,javascript文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-667905.html

到了這里,關(guān)于html動(dòng)態(tài)愛(ài)心代碼【四】(附源碼)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包