国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

html愛心特效代碼——愛心代碼

這篇具有很好參考價(jià)值的文章主要介紹了html愛心特效代碼——愛心代碼。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

今天閑來無事,教大家一個(gè)哄妹子的小case。我們需要創(chuàng)建一個(gè)心形圖案,按照心形圖案的位置和長度,對所創(chuàng)建的字符串進(jìn)行截?cái)嗖⒃谒璧奈恢蒙陷敵?,最終能呈現(xiàn)在屏幕上滿滿的愛心。廢話不多說,直接上源碼看效果 ~
html愛心特效代碼——愛心代碼文章來源地址http://www.zghlxwxcb.cn/news/detail-491506.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
  <style>
  html, body {
  height: 100%;
  padding: 0;
  margin: 0;
  background: #000;
}
canvas {
  position: absolute;
  width: 100%;
  height: 100%;
}
  </style>
 </HEAD>

 <BODY>
  <canvas id="pinkboard"></canvas>
  <script>
  /*
 * Settings
 */
var settings = {
  particles: {
    length:   500, // maximum amount of particles
    duration:   2, // particle duration in sec
    velocity: 100, // particle velocity in pixels/sec
    effect: -0.75, // play with this for a nice effect
    size:      30, // particle size in pixels
  },
};

/*
 * RequestAnimationFrame polyfill by Erik M?ller
 */
(function(){var b=0;var c=["ms","moz","webkit","o"];for(var a=0;a<c.length&&!window.requestAnimationFrame;++a){window.requestAnimationFrame=window[c[a]+"RequestAnimationFrame"];window.cancelAnimationFrame=window[c[a]+"CancelAnimationFrame"]||window[c[a]+"CancelRequestAnimationFrame"]}if(!window.requestAnimationFrame){window.requestAnimationFrame=function(h,e){var d=new Date().getTime();var f=Math.max(0,16-(d-b));var g=window.setTimeout(function(){h(d+f)},f);b=d+f;return g}}if(!window.cancelAnimationFrame){window.cancelAnimationFrame=function(d){clearTimeout(d)}}}());

/*
 * Point class
 */
var Point = (function() {
  function Point(x, y) {
    this.x = (typeof x !== 'undefined') ? x : 0;
    this.y = (typeof y !== 'undefined') ? y : 0;
  }
  Point.prototype.clone = function() {
    return new Point(this.x, this.y);
  };
  Point.prototype.length = function(length) {
    if (typeof length == 'undefined')
      return Math.sqrt(this.x * this.x + this.y * this.y);
    this.normalize();
    this.x *= length;
    this.y *= length;
    return this;
  };
  Point.prototype.normalize = function() {
    var length = this.length();
    this.x /= length;
    this.y /= length;
    return this;
  };
  return Point;
})();

/*
 * Particle class
 */
var Particle = (function() {
  function Particle() {
    this.position = new Point();
    this.velocity = new Point();
    this.acceleration = new Point();
    this.age = 0;
  }
  Particle.prototype.initialize = function(x, y, dx, dy) {
    this.position.x = x;
    this.position.y = y;
    this.velocity.x = dx;
    this.velocity.y = dy;
    this.acceleration.x = dx * settings.particles.effect;
    this.acceleration.y = dy * settings.particles.effect;
    this.age = 0;
  };
  Particle.prototype.update = function(deltaTime) {
    this.position.x += this.velocity.x * deltaTime;
    this.position.y += this.velocity.y * deltaTime;
    this.velocity.x += this.acceleration.x * deltaTime;
    this.velocity.y += this.acceleration.y * deltaTime;
    this.age += deltaTime;
  };
  Particle.prototype.draw = function(context, image) {
    function ease(t) {
      return (--t) * t * t + 1;
    }
    var size = image.width * ease(this.age / settings.particles.duration);
    context.globalAlpha = 1 - this.age / settings.particles.duration;
    context.drawImage(image, this.position.x - size / 2, this.position.y - size / 2, size, size);
  };
  return Particle;
})();

/*
 * ParticlePool class
 */
var ParticlePool = (function() {
  var particles,
      firstActive = 0,
      firstFree   = 0,
      duration    = settings.particles.duration;
  
  function ParticlePool(length) {
    // create and populate particle pool
    particles = new Array(length);
    for (var i = 0; i < particles.length; i++)
      particles[i] = new Particle();
  }
  ParticlePool.prototype.add = function(x, y, dx, dy) {
    particles[firstFree].initialize(x, y, dx, dy);
    
    // handle circular queue
    firstFree++;
    if (firstFree   == particles.length) firstFree   = 0;
    if (firstActive == firstFree       ) firstActive++;
    if (firstActive == particles.length) firstActive = 0;
  };
  ParticlePool.prototype.update = function(deltaTime) {
    var i;
    
    // update active particles
    if (firstActive < firstFree) {
      for (i = firstActive; i < firstFree; i++)
        particles[i].update(deltaTime);
    }
    if (firstFree < firstActive) {
      for (i = firstActive; i < particles.length; i++)
        particles[i].update(deltaTime);
      for (i = 0; i < firstFree; i++)
        particles[i].update(deltaTime);
    }
    
    // remove inactive particles
    while (particles[firstActive].age >= duration && firstActive != firstFree) {
      firstActive++;
      if (firstActive == particles.length) firstActive = 0;
    }
    
    
  };
  ParticlePool.prototype.draw = function(context, image) {
    // draw active particles
    if (firstActive < firstFree) {
      for (i = firstActive; i < firstFree; i++)
        particles[i].draw(context, image);
    }
    if (firstFree < firstActive) {
      for (i = firstActive; i < particles.length; i++)
        particles[i].draw(context, image);
      for (i = 0; i < firstFree; i++)
        particles[i].draw(context, image);
    }
  };
  return ParticlePool;
})();

/*
 * Putting it all together
 */
(function(canvas) {
  var context = canvas.getContext('2d'),
      particles = new ParticlePool(settings.particles.length),
      particleRate = settings.particles.length / settings.particles.duration, // particles/sec
      time;
  
  // get point on heart with -PI <= t <= PI
  function pointOnHeart(t) {
    return new Point(
      160 * Math.pow(Math.sin(t), 3),
      130 * Math.cos(t) - 50 * Math.cos(2 * t) - 20 * Math.cos(3 * t) - 10 * Math.cos(4 * t) + 25
    );
  }
  
  // creating the particle image using a dummy canvas
  var image = (function() {
    var canvas  = document.createElement('canvas'),
        context = canvas.getContext('2d');
    canvas.width  = settings.particles.size;
    canvas.height = settings.particles.size;
    // helper function to create the path
    function to(t) {
      var point = pointOnHeart(t);
      point.x = settings.particles.size / 2 + point.x * settings.particles.size / 350;
      point.y = settings.particles.size / 2 - point.y * settings.particles.size / 350;
      return point;
    }
    // create the path
    context.beginPath();
    var t = -Math.PI;
    var point = to(t);
    context.moveTo(point.x, point.y);
    while (t < Math.PI) {
      t += 0.01; // baby steps!
      point = to(t);
      context.lineTo(point.x, point.y);
    }
    context.closePath();
    // create the fill
    context.fillStyle = '#ea80b0';
    context.fill();
    // create the image
    var image = new Image();
    image.src = canvas.toDataURL();
    return image;
  })();
  
  // render that thing!
  function render() {
    // next animation frame
    requestAnimationFrame(render);
    
    // update time
    var newTime   = new Date().getTime() / 1000,
        deltaTime = newTime - (time || newTime);
    time = newTime;
    
    // clear canvas
    context.clearRect(0, 0, canvas.width, canvas.height);
    
    // create new particles
    var amount = particleRate * deltaTime;
    for (var i = 0; i < amount; i++) {
      var pos = pointOnHeart(Math.PI - 2 * Math.PI * Math.random());
      var dir = pos.clone().length(settings.particles.velocity);
      particles.add(canvas.width / 2 + pos.x, canvas.height / 2 - pos.y, dir.x, -dir.y);
    }
    
    // update and draw particles
    particles.update(deltaTime);
    particles.draw(context, image);
  }
  
  // handle (re-)sizing of the canvas
  function onResize() {
    canvas.width  = canvas.clientWidth;
    canvas.height = canvas.clientHeight;
  }
  window.onresize = onResize;
  
  // delay rendering bootstrap
  setTimeout(function() {
    onResize();
    render();
  }, 10);
})(document.getElementById('pinkboard'));
  </script>
 </BODY>
</HTML>


到了這里,關(guān)于html愛心特效代碼——愛心代碼的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 流星特效案例代碼

    流星特效案例代碼

    實(shí)際效果,代碼下載即可使用 ?流星圖片 ? !-- ?描述: 流星特效 ?作者: Jack GUO ?日期: 20230727 -- template ? div class=\\\"wrap-container sn-container\\\" ? ? div class=\\\"pd-main-left\\\" ? ? ? div class=\\\"yun-container\\\" ? ? ? ? div class=\\\"yun-tree\\\"/div ? ? ? ? div class=\\\"line-fs\\\"/div ? ? ? ? div class=\\\"line-fs\\\"/div ? ? ?

    2024年02月15日
    瀏覽(24)
  • python流星雨特效代碼復(fù)制,python好看的流星雨代碼

    python流星雨特效代碼復(fù)制,python好看的流星雨代碼

    大家好,小編為大家解答python流星雨特效代碼需要什么模塊的問題。很多人還不知道python流星雨特效代碼微信,現(xiàn)在讓我們一起來看看吧! hello,大家好,我是wangzirui32,今天我們來學(xué)習(xí)如何用Pygame制作一場漂亮的流星雨。 開始學(xué)習(xí)吧! 文章目錄 前言 1. 素材圖片 2. 項(xiàng)目結(jié)構(gòu)

    2024年02月03日
    瀏覽(45)
  • 前端代碼分享——星空背景特效(內(nèi)含源碼)

    前端代碼分享——星空背景特效(內(nèi)含源碼)

    打開網(wǎng)頁效果最好哦 提供的JavaScript代碼是一個(gè)名為\\\"WarpDrive\\\"的jQuery插件,它創(chuàng)建了一個(gè)星空動畫,類似于科幻媒體(如《星際迷航》)中所看到的\\\"超光速\\\"效果。 提供的JavaScript代碼是一個(gè)名為\\\"WarpDrive\\\"的jQuery插件,它創(chuàng)建了一個(gè)星空動畫,類似于科幻媒體(如《星際迷航》)

    2024年02月14日
    瀏覽(19)
  • Python煙花代碼,用Python制作一個(gè)煙花特效

    Python煙花代碼,用Python制作一個(gè)煙花特效

    Python實(shí)現(xiàn)浪漫的煙花特效 現(xiàn)在很多地方都不能放煙花了,既然看不到, 那作為程序猿的我們還不能自己用代碼做一個(gè)嗎? 今天就帶大家用代碼做一個(gè)煙花特效吧。 pygame介紹 關(guān)于Pygame的基本信息,pygame是什么,誰會被Pygame吸引,并且在哪里找到它。 Pygame是被設(shè)計(jì)用來寫游戲

    2024年02月08日
    瀏覽(25)
  • python炫酷特效代碼簡單,python制作的炫酷動畫

    python炫酷特效代碼簡單,python制作的炫酷動畫

    本篇文章給大家談?wù)刾ython炫酷特效代碼簡單,以及python好看的圖案代碼,希望對各位有所幫助,不要忘了收藏本站喔。 可以生成下面這種圖 import random import turtle def random_color(): ? ? rgbl=[255,0,0] ? ? random.shuffle(rgbl) ? ? return tuple(rgbl) def koch(size,n): ? ? if n==0: ? ? ? ? (size) ?

    2024年02月07日
    瀏覽(20)
  • Windows亞克力特效代碼實(shí)現(xiàn)(Dev c++可以編譯通過)

    頭文件下載鏈接,調(diào)用 include\\\"arcrylic.h\\\" 即可

    2024年02月03日
    瀏覽(19)
  • 28個(gè)炫酷的CSS特效動畫示例(含源代碼)

    28個(gè)炫酷的CSS特效動畫示例(含源代碼)

    CSS是網(wǎng)頁的三駕馬車之一,是對頁面布局的總管家,2024年了,這里列出28個(gè)超級炫酷的純CSS動畫示例,讓您的網(wǎng)站更加炫目多彩。 效果圖: 點(diǎn)擊查看示例源代碼 效果圖: 點(diǎn)擊查看示例源代碼 效果圖: 點(diǎn)擊查看示例源代碼 效果圖: 點(diǎn)擊查看示例源代碼 效果圖: 點(diǎn)擊查看示

    2024年01月16日
    瀏覽(28)
  • 28個(gè)炫酷的純CSS特效動畫示例(含源代碼)

    28個(gè)炫酷的純CSS特效動畫示例(含源代碼)

    CSS是網(wǎng)頁的三駕馬車之一,是對頁面布局的總管家,2024年了,這里列出28個(gè)超級炫酷的純CSS動畫示例,讓您的網(wǎng)站更加炫目多彩。 效果圖: 點(diǎn)擊查看示例源代碼 效果圖: 點(diǎn)擊查看示例源代碼 效果圖: 點(diǎn)擊查看示例源代碼 效果圖: 點(diǎn)擊查看示例源代碼 效果圖: 點(diǎn)擊查看示

    2024年01月20日
    瀏覽(27)
  • 網(wǎng)站登錄界面制作(three.js 3D特效背景)+ boostrap導(dǎo)航欄實(shí)現(xiàn) + jQuery移動窗口【附加源代碼】

    網(wǎng)站登錄界面制作(three.js 3D特效背景)+ boostrap導(dǎo)航欄實(shí)現(xiàn) + jQuery移動窗口【附加源代碼】

    學(xué)過Web前端的許多小伙伴都會面對門戶網(wǎng)站制作的大作業(yè)報(bào)告,這里給大家分享一下我的前端大作業(yè)。后續(xù)還會繼續(xù)更新,喜歡的小伙伴可以點(diǎn)個(gè)贊。 注意上述為動態(tài)界面: 下面的是表單的JS源代碼: 下面是3D動態(tài)例子的源代碼: 注意中間的窗口是移動的; 下面是移動窗口

    2024年02月07日
    瀏覽(25)
  • 情人節(jié)定制:HTML5 Canvas全屏七夕愛心表白特效

    情人節(jié)定制:HTML5 Canvas全屏七夕愛心表白特效

    “這個(gè)世界亂糟糟的而你干干凈凈可以懸在我心上做太陽和月亮?!保呦?jié)表白日,你要錯(cuò)過嗎?如果你言辭不善,羞于開口的話,可以使用 html5 canvas 制作浪漫的七夕愛心表白動畫特效,全屏的愛心和表白語,了解一下!? ?? 最后,祝天下有情人終成眷屬 ??

    2024年02月11日
    瀏覽(95)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包