js浪漫满屏爱心表白动画特效

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>js表白</title>
    <link rel="stylesheet" href="css/index.css">
</head>
<body>

<div class="textCon">
        <div class="words">我的小花花,今天是认识你的第</div>
        <div class="days">
            <span class="days-number">1921</span>
            <span class="days-label"></span>
        </div>
        <div class="seconds">15 hours 24 minutes 30 seconds</div>
</div>

<div class="heart"></div>
<script src="js/index.js"></script>
<script src="js/love.js"></script>

</body>
</html>
*{
    margin: 0;
    padding:0;
}
html,body{
    width:100%;
    height:100%;
    /*text-align: center;*/
    background-color: #ffc5b3;
    position:absolute;
    top:50%;
    left:50%;
    transform:translate(-50%,-50%);
    -webkit-transform:translate(-50%,-50%);
    -ms-transform:translate(-50%,-50%);
    -moz-transform:translate(-50%,-50%);
    -o-transform:translate(-50%,-50%);
	background-image: radial-gradient(#ffeded, #ffc7c7);
}
.textCon{
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    width:700px;
    height:60px;
    margin:50px auto;
}
.text{
    font-size:48px;
}
.heart{
    width:80px;
    height:80px;
    background-color:#cc2a5d;
    margin:200px auto;
    position: relative;
    transform: rotate(45deg);
    animation: heart 1s ease-in infinite;
}
.heart::before,
.heart::after{
    content:'';
    width:100%;
    height:100%;
    background-color:#cc2a5d;
    border-radius: 50%;
}
.heart::before{
    position: absolute;
    top:0;
    left:0;
    transform: translateX(-50%);
}
.heart::after{
    position: absolute;
    top:0;
    left:0;
    transform: translateY(-50%);
}
@keyframes heart{
    0%{
        transform: scale(0.8) rotate(45deg);
        opacity: 0.8;
    }
    50%{
        transform: scale(1) rotate(45deg);
        opacity: 1;
    }
    100%{
        transform: scale(0.8) rotate(45deg);
        opacity: 0.8;
    }
}
.textCon .item{
    position: absolute;
    opacity: 0;
    background-color:#cc2a5d;
    transform: rotate(45deg);
    animation: hearts 3s ease-in infinite;
}
.textCon .item::before,
.textCon .item::after{
    content:'';
    width:100%;
    height:100%;
    background-color:#cc2a5d;
    position: absolute;
    top:0;
    left:0;
    border-radius: 50%;
}
.textCon .item::before{
    transform: translateX(-50%);
}
.textCon .item::after{
    transform: translateY(-50%);
}
@keyframes hearts{
    0%{
        opacity: 0;
        transform: translateY(0%) rotate(45deg);
    }
    20%{
        opacity: 0.8;
        transform: translateY(-20%) rotate(45deg);
    }
    100%{
        opacity: 0;
        transform: translateY(-1000%) rotate(45deg);
    }
}
.days-label {
    font-size: 30px;
}

.seconds {
    margin-top: 10px;
    font-size: 32px;
    font-family: "Monda_bo", Georgia, sans-serif;
    width: auto;
    text-align: center;
}

.seconds-label {
    margin-top: 32px;
    font-size: 32px;
    font-family: "Monda_no", Georgia, sans-serif;
    width: auto;
    text-align: center;
}

.container {
    position: absolute;
}
.days {
    font-size: 40px;
    width: auto;
    text-align: center;
}
.words {
    font-size: 50px;
    font-family: 'Regular', cursive;
    width: auto;
    text-align: center;
}

var arr = "2019-05-29 18:06:00".split(/[- :]/);//改这里
var box = document.getElementsByClassName('textCon')[0];
function init() {
    var width = box.offsetWidth;
    var count = parseInt(width / 50 * 5);
    for (var i = 0; i < count; i++) {
        var size = parseInt(ran(60, 120) / 10);
        var ele = document.createElement('div');
        ele.classList.add('item');
        ele.style.width = size + 'px';
        ele.style.height = size + 'px';
        ele.style.left = ran(0, 95) + '%';
        ele.style.top = ran(20, 80) + '%';
        ele.style.animationDelay = ran(0, 30) / 10 + 's';
        box.appendChild(ele);
    }
}
function ran(min, max) {
    min = parseInt(min);
    max = parseInt(max);
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
function timer_start(){

    var start_time = new Date(arr[0], arr[1]-1, arr[2], arr[3], arr[4], arr[5]);
    // var start_time =  new Date(beginTime);
    // var start_time = Date.parse(beginTime);
    var duration = parseInt(new Date()- start_time)/1000;
    var seconds = parseInt( duration % 60);
    if (seconds < 10)
        seconds = "0" + seconds;
    duration = parseInt(duration / 60);
    var minutes = duration % 60;
    if (minutes < 10)
        minutes = "0" + minutes;
    duration = parseInt(duration / 60);
    var hours = duration % 24;
    if (hours < 10)
        hours = "0" + hours;
    duration = parseInt(duration / 24);
    var days = duration;
    document.getElementsByClassName('days-number')[0].innerHTML = ("" +days);
    document.getElementsByClassName('seconds')[0].innerHTML = (hours + " 时 " + minutes + " 分 " + seconds + " 秒");
}
window.setInterval(timer_start,1000);
timer_start();
init();

  • 6
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值