首页 前端知识 【圣诞表白特效----HTML CSS JS实现(附效果 源代码)】(2)

【圣诞表白特效----HTML CSS JS实现(附效果 源代码)】(2)

2024-05-26 01:05:53 前端知识 前端哥 58 465 我要收藏

var ww,wh;

function onResize(){

ww = canvas.width = window.innerWidth;

wh = canvas.height = window.innerHeight;

}

ctx.strokeStyle = “red”;

ctx.shadowBlur = 25;

ctx.shadowColor = “hsla(0, 100%, 60%,0.5)”;

var precision = 100;

var hearts = [];

var mouseMoved = false;

function onMove(e){

mouseMoved = true;

if(e.type === “touchmove”){

hearts.push(new Heart(e.touches[0].clientX, e.touches[0].clientY));

hearts.push(new Heart(e.touches[0].clientX, e.touches[0].clientY));

}

else{

hearts.push(new Heart(e.clientX, e.clientY));

hearts.push(new Heart(e.clientX, e.clientY));

}

}

var Heart = function(x,y){

this.x = x || Math.random()*ww;

this.y = y || Math.random()*wh;

this.size = Math.random()*2 + 1;

this.shadowBlur = Math.random() * 10;

this.speedX = (Math.random()+0.2-0.6) * 8;

this.speedY = (Math.random()+0.2-0.6) * 8;

this.speedSize = Math.random()*0.05 + 0.01;

this.opacity = 1;

this.vertices = [];

for (var i = 0; i < precision; i++) {

var step = (i / precision - 0.5) * (Math.PI * 2);

var vector = {

x : (15 * Math.pow(Math.sin(step), 3)),

y : -(13 * Math.cos(step) - 5 * Math.cos(2 * step) - 2 * Math.cos(3 * step) - Math.cos(4 * step))

}

this.vertices.push(vector);

}

}

Heart.prototype.draw = function(){

this.size -= this.speedSize;

this.x += this.speedX;

this.y += this.speedY;

ctx.save();

ctx.translate(-1000,this.y);

ctx.scale(this.size, this.size);

ctx.beginPath();

for (var i = 0; i < precision; i++) {

var vector = this.vertices[i];

ctx.lineTo(vector.x, vector.y);

}

ctx.globalAlpha = this.size;

ctx.shadowBlur = Math.round((3 - this.size) * 10);

ctx.shadowColor = “hsla(0, 100%, 60%,0.5)”;

ctx.shadowOffsetX = this.x + 1000;

ctx.globalCompositeOperation = “screen”

ctx.closePath();

ctx.fill()

ctx.restore();

};

function render(a){

requestAnimationFrame(render);

hearts.push(new Heart())

ctx.clearRect(0,0,ww,wh);

for (var i = 0; i < hearts.length; i++) {

hearts[i].draw();

if(hearts[i].size <= 0){

hearts.splice(i,1);

i–;

}

}

}

onResize();

window.addEventListener(“mousemove”, onMove);

window.addEventListener(“touchmove”, onMove);

window.addEventListener(“resize”, onResize);

requestAnimationFrame(render);

window.οnlοad=function starttime(){

time(h1,‘2017,7,9’); // 在一起的时间

ptimer = setTimeout(starttime,1000); // 添加计时器

}

function time(obj,futimg){

var nowtime = new Date().getTime(); // 现在时间转换为时间戳

var futruetime = new Date(futimg).getTime(); // 未来时间转换为时间戳

var msec = nowtime-futruetime; // 毫秒 未来时间-现在时间

var time = (msec/1000); // 毫秒/1000

var day = parseInt(time/86400); // 天 246060*1000

var hour = parseInt(time/3600)-24day; // 小时 6060 总小时数-过去的小时数=现在的小时数

var minute = parseInt(time600/60); // 分 -(day*24) 以60秒为一整份 取余 剩下秒数 秒数/60 就是分钟数

var second = parseInt(time`); // 以60秒为一整份 取余 剩下秒数

obj.innerHTML=“XX
咱俩在一起的时间已经:
”+day+“天”+hour+“小时”+minute+“分”+second+“秒”+“了
圣诞之夜即将来临,真爱来了,我们要好好把握。
不管面临多大的压力,不管前面的路如何崎岖.
不管经历过什么,我仍坚信最浪漫的事就是和你一起慢慢变老.
相信中间的计时器,将永远继续下去,直至数据溢出.”

return true;

}

最后

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。

因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!

如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
droid开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!**

如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

转载请注明出处或者链接地址:https://www.qianduange.cn//article/9576.html
标签
评论
发布的文章

html5怎么实现语音搜索

2024-06-01 10:06:32

HTML5

2024-02-27 11:02:15

HTML - 头部元素

2024-06-01 10:06:06

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!