http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 3738|回复: 1

[JavaScript] js-原生爱心表白特效

[复制链接]
发表于 2021-7-7 17:11:00 | 显示全部楼层 |阅读模式
    今天看了一个爱心表白的效果,给大家分享一下。有需要的朋友拿走不谢!
    效果:
    企业微信截图_16256484947930.png
    css样式:
   
[CSS] 纯文本查看 复制代码
*{
    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);
}
.start_time{display: none;}
.conts{
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    width:700px;
    height:60px;
    margin:50px auto;
    color: red;
}
.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;
    }
}
.conts .item{
    position: absolute;
    opacity: 0;
    background-color:#cc2a5d;
    transform: rotate(45deg);
    animation: hearts 3s ease-in infinite;
}
.conts .item::before,
.conts .item::after{
    content:'';
    width:100%;
    height:100%;
    background-color:#cc2a5d;
    position: absolute;
    top:0;
    left:0;
    border-radius: 50%;
}
.conts .item::before{
    transform: translateX(-50%);
}
.conts .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);
    }
}
.day_text {
    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;
}
.texts {
    font-size: 50px;
    font-family: 'Regular', cursive;
    width: auto;
    text-align: center;
}

    HTML:
   
[HTML] 纯文本查看 复制代码
<div class="conts">
    <div class="texts">我的女孩,今天是我们相爱的第</div>
    <div class="days">
        <span class="day_num"></span>
        <span class="day_text">天</span>
    </div>
    <div class="seconds"></div>
</div>

<div class="heart"></div>
<div class="start_time">2019-08-27 20:06:00</div><!--开始时间,在这里修改时间即可。-->

    js代码

   
[JavaScript] 纯文本查看 复制代码
var arr = document.getElementsByClassName('start_time')[0].innerHTML.split(/[- :]/);
var box = document.getElementsByClassName('conts')[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 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('day_num')[0].innerHTML = ("" +days);
    document.getElementsByClassName('seconds')[0].innerHTML = (hours + " 时 " + minutes + " 分 " + seconds + " 秒");
}
window.setInterval(timer_start,1000);
timer_start();
init();

    以上就是实现的全部代码了,源码中还有点击出现爱心效果,如需源码,请点击》》 爱心.zip (3.44 KB, 下载次数: 0)


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2021-7-8 14:36:08 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-11-22 07:43

© 2014-2021

快速回复 返回顶部 返回列表