限时优惠活动
亲爱的苦力吧用户,我们为了回馈新老用户一直以来的鼎力支持,即日起(2025-02-06至2025-03-06)凡是购买苦力吧VIP/充值K币的新老用户,都直接可获得买一送一的优惠馈赠。例如:购买一个月的VIP会员可直接获得两个月的VIP会员;充值100K币可直接获得200K币,以此类推!有任何疑问可联系在线客服,感谢各位用户对苦力吧素材的信任与厚爱,我们将一如既往的给大家上新更多优质的素材源码,祝大家开工大吉、工作顺利、心想事成。

html5情人节爱心背景动画特效

所属分类: 网页特效-动画效果    2024-03-21 01:39:12

html5情人节爱心背景动画特效 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

html5情人节爱心背景动画特效(共1个文件)

    • index.html

使用方法

  • code
  • source
  1. var canvas = document.querySelector("canvas"),
  2. ctx = canvas.getContext("2d");
  3. var ww,wh;
  4. function onResize(){
  5. ww = canvas.width = window.innerWidth;
  6. wh = canvas.height = window.innerHeight;
  7. }
  8. ctx.strokeStyle = "red";
  9. ctx.shadowBlur = 25;
  10. ctx.shadowColor = "hsla(0, 100%, 60%,0.5)";
  11. var precision = 100;
  12. var hearts = [];
  13. var mouseMoved = false;
  14. function onMove(e){
  15. mouseMoved = true;
  16. if(e.type === "touchmove"){
  17. hearts.push(new Heart(e.touches[0].clientX, e.touches[0].clientY));
  18. hearts.push(new Heart(e.touches[0].clientX, e.touches[0].clientY));
  19. }
  20. else{
  21. hearts.push(new Heart(e.clientX, e.clientY));
  22. hearts.push(new Heart(e.clientX, e.clientY));
  23. }
  24. }
  25. var Heart = function(x,y){
  26. this.x = x || Math.random()*ww;
  27. this.y = y || Math.random()*wh;
  28. this.size = Math.random()*2 + 1;
  29. this.shadowBlur = Math.random() * 10;
  30. this.speedX = (Math.random()+0.2-0.6) * 8;
  31. this.speedY = (Math.random()+0.2-0.6) * 8;
  32. this.speedSize = Math.random()*0.05 + 0.01;
  33. this.opacity = 1;
  34. this.vertices = [];
  35. for (var i = 0; i < precision; i++) {
  36. var step = (i / precision - 0.5) * (Math.PI * 2);
  37. var vector = {
  38. x : (15 * Math.pow(Math.sin(step), 3)),
  39. y : -(13 * Math.cos(step) - 5 * Math.cos(2 * step) - 2 * Math.cos(3 * step) - Math.cos(4 * step))
  40. }
  41. this.vertices.push(vector);
  42. }
  43. }
  44. Heart.prototype.draw = function(){
  45. this.size -= this.speedSize;
  46. this.x += this.speedX;
  47. this.y += this.speedY;
  48. ctx.save();
  49. ctx.translate(-1000,this.y);
  50. ctx.scale(this.size, this.size);
  51. ctx.beginPath();
  52. for (var i = 0; i < precision; i++) {
  53. var vector = this.vertices[i];
  54. ctx.lineTo(vector.x, vector.y);
  55. }
  56. ctx.globalAlpha = this.size;
  57. ctx.shadowBlur = Math.round((3 - this.size) * 10);
  58. ctx.shadowColor = "hsla(0, 100%, 60%,0.5)";
  59. ctx.shadowOffsetX = this.x + 1000;
  60. ctx.globalCompositeOperation = "screen"
  61. ctx.closePath();
  62. ctx.fill()
  63. ctx.restore();
  64. };
  65. function render(a){
  66. requestAnimationFrame(render);
  67. hearts.push(new Heart())
  68. ctx.clearRect(0,0,ww,wh);
  69. for (var i = 0; i < hearts.length; i++) {
  70. hearts[i].draw();
  71. if(hearts[i].size <= 0){
  72. hearts.splice(i,1);
  73. i--;
  74. }
  75. }
  76. }
  77. onResize();
  78. window.addEventListener("mousemove", onMove);
  79. window.addEventListener("touchmove", onMove);
  80. window.addEventListener("resize", onResize);
  81. requestAnimationFrame(render);
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);

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 动画效果

CSS3动态背景动画会员登录代码特效

单击input文本框,自动边长向两边拉伸,背景带css3动画方块向上滚动。
  动画效果
 1404  0

jquery数字滚动计数器动画特效代码

页面加载后,可以看到数字滚动的动画效果,数字从0开始一直翻滚到实际的数值。
  动画效果
 3388  0

jquery+CSS3表单提交信封发送动画特效

一款信封发送CSS3动画效果,提交表单信息后,触发红色信封合起且向右飞走动画特效。
  动画效果
 7216  0

纯CSS3实现的右下角浮动按钮动画特效

一款基于css制作的浮动按钮动画效果,鼠标点击右下角按钮,可触发显示带图标的小按钮菜单,支持关闭。
  动画效果
 4272  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论