前端超炫表白干货(一)

表白代码,送给你爱的人
梦码在这里首先很感谢来看此博客的同学们,如果你觉得还可以,别忘记点个赞加关注哦,别忘记了这才是前端表白干货(一)哦,后面还有二、三、四。。。。。。错过了就可惜了

这次梦码分享的是一个前端代码,不会的同学复制代码写在后缀为html的文件里浏览器打开就可以了,也比较方便,如果要改页面显示的内容(比如加上对方名字啥的),可以在文件里面直接改。最后再把文件发给你喜欢的那个他(她),用浏览器打开,说不定从此就能告别单身生活了呢。哈哈哈。。
首先我们先看看效果

在这里插入图片描述

这个不是静态的哦,他是动态的,梦码有点懒,就只截了个图,各位同学别怪梦码,想看就自己去运行,废话也不多说了,我们直接上代码吧!

javascript"><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>love</title>
<link href="favicon.ico" rel="shortcut icon" />
<style>
body{
  overflow: hidden;
  margin: 0;
}
h1{
  position: fixed;
  top: 50%;
  left: 0;
  width: 100%;
  text-align: center;
  transform:translateY(-50%);
  font-family: 'Love Ya Like A Sister', cursive;
  font-size: 40px;
  color: #c70012;
  padding: 0 20px;
}
h1 span{
    font-size:20px;
}
</style>

</head>
<body>
<h1 id="h1"></h1>
<canvas></canvas> 

<script>
var canvas = document.querySelector("canvas"),
  ctx = canvas.getContext("2d");

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.onload=function starttime(){
        time(h1,'2017,7,4');     // 在一起的时间
        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); // 天  24*60*60*1000 
        var hour = parseInt(time/3600)-24*day;    // 小时 60*60 总小时数-过去的小时数=现在的小时数 
        var minute = parseInt(time%3600/60); // 分 -(day*24) 以60秒为一整份 取余 剩下秒数 秒数/60 就是分钟数
        var second = parseInt(time%60);  // 以60秒为一整份 取余 剩下秒数
//              console.log(hour+":"+minute+":"+second)
//              alert(hour)
        obj.innerHTML="亲爱的<br>咱俩在一起的时间已经:<br>"+day+"天"+hour+"小时"+minute+"分"+second+"秒"+"了<br><span>一时间不知道从哪说起,真爱来了,我们要好好把握。<br>不管面临多大的压力,不管前面的路如何崎岖.<br>不管经历过什么,我仍坚信最浪漫的事就是和你一起慢慢变老.<br>相信中间的计时器,将永远继续下去,直至数据溢出.</span>"

        return true;
    }
</script>

</body>
</html>

古曰:“程序员不配拥有爱情”
梦码可能为了一心成为一个优秀的程序员,至今单身。
我有一个梦想
每一位程序员都能拥有一个属于自己的爱情,谈一场轰轰烈烈的恋爱,来一场说走就走的旅行,如果你心里一直有个他(她),就赶紧行动吧,你不试试怎么知道自己不行呢?说不定那个他(她)就一直在等你呢?不管他(她)是不是在等你,微信公众号梦码城一直在等你哦!

结语
如果你觉得这篇博客还可以,别忘记点个赞加个关注再走哦。


http://www.niftyadmin.cn/n/941771.html

相关文章

分块入门总结

前言 这一切都是基于「分块」数列分块入门1 – 9&#xff0c;也就是对其的总结。 链接 #6277. 数列分块入门 1 数列分块入门1 LibreOj 6277_Carry_hkr的博客-CSDN博客 #6278. 数列分块入门 2 …

Python——必备魔法方法

Python面向对象——魔法方法 一&#xff0c;定义 在python中&#xff0c;有一些内置特定的方法&#xff0c;这些方法在进行特定的操作时会自动被调用&#xff0c;称为魔法方法&#xff08;Magic Method&#xff09;&#xff0c;以“__"&#xff08;英文&#xff09;双下…

Codeforces 165C Another Problem on Strings(尺取法)

题目 题目链接Problem - 165C - Codeforces C. Another Problem on Strings 2 seconds 256 megabytes A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and …

Maximum Profit(C++最大利益简单算法)

竞赛训练1 入门问题&#xff1a;Maximum Profit 题目&#xff1a; 外汇交易可以通过兑换不同国家的货币以赚取汇率差。比如1美元兑换100日元时购入1000美元&#xff0c;然后等汇率变动到一美元兑换108日元时再卖出&#xff0c;这样就可以赚取(108-100)*10008000日元。 现在请将…

Codeforces 846A - Curriculum Vitae

题目 A. Curriculum Vitae 1 second 256 megabytes Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has…

必学算法——深度优先搜索(DFS)

深度优先搜索 深度优先搜索 (DFS, Depth-First Search) 是搜索的手段之一 。 它从某个状态开始&#xff0c; 不断地转移状态直到无法转移&#xff0c;然后回退到前一步的状态&#xff0c;继续转移到其他状态&#xff0c;如此不断重复&#xff0c;直至找到最终的解。例如求解数独…

牛客练习赛86 C - 取钱(贪心)

题目 题目描述 某个国家的货币体系里有 种面值不同的纸币&#xff0c;从小到大面值分别是 当取款人去机取款 元的时候&#xff0c;机按一种贪心的策略给取款人发放钞票&#xff0c;策略如下&#xff1a; 首先&#xff0c;已发放钞票的集合是空集&#xff0c;每一次 机都…

前端基础——HTML总结

一、HTML HTML&#xff08;HyperText Mark-up Language&#xff09;是超文本标记语言。 详细学习参考W3C网址以及菜鸟教程 网页实现基本结构 HTML&#xff1a;页面结构CSS&#xff1a;页面样式&#xff0c;如元素大小、颜色、位置、隐藏显示、部分动效等JavaScript&#xf…