• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

李峋同款爱心加照片

武飞扬头像
杨乙燃5132
帮助1

一、源码

  1.  
    <!DOCTYPE html>
  2.  
    <html>
  3.  
    <head>
  4.  
    <meta charset="utf-8" />
  5.  
    <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script>
  6.  
    <style type="text/css">
  7.  
    @import url("https://fonts.谷歌apis.com/css?family=Montserrat:200,300,400,600");
  8.  
    .more-pens {
  9.  
    position: fixed;
  10.  
    left: 20px;
  11.  
    bottom: 20px;
  12.  
    z-index: 10;
  13.  
    font-family: "Montserrat";
  14.  
    font-size: 12px;
  15.  
    }
  16.  
     
  17.  
    a.white-mode,
  18.  
    a.white-mode:link,
  19.  
    a.white-mode:visited,
  20.  
    a.white-mode:active {
  21.  
    font-family: "Montserrat";
  22.  
    font-size: 12px;
  23.  
    text-decoration: none;
  24.  
    /* background: #212121; */
  25.  
    padding: 4px 8px;
  26.  
    color: #f7f7f7;
  27.  
    }
  28.  
     
  29.  
    a.white-mode:hover,
  30.  
    a.white-mode:link:hover,
  31.  
    a.white-mode:visited:hover,
  32.  
    a.white-mode:active:hover {
  33.  
    background: #edf3f8;
  34.  
    color: #212121;
  35.  
    }
  36.  
     
  37.  
    .title {
  38.  
    z-index: 9999 !important;
  39.  
    position: absolute;
  40.  
    left: 50%;
  41.  
    top: 42%;
  42.  
    transform: translateX(-50%) translateY(-50%);
  43.  
    font-family: "Montserrat";
  44.  
    text-align: center;
  45.  
    width: 100%;
  46.  
    }
  47.  
     
  48.  
    .title h1 {
  49.  
    z-index: 99;
  50.  
    position: relative;
  51.  
    color: #fff;
  52.  
    font-weight: 100;
  53.  
    font-size: 70px;
  54.  
    padding: 0;
  55.  
    margin: 0;
  56.  
    line-height: 1;
  57.  
    text-shadow: 0 0 10px #ff006c, 0 0 20px #ff006c, 0 0 30px #ff006c,
  58.  
    0 0 40px #ff417d, 0 0 70px #ff417d, 0 0 80px #ff417d,
  59.  
    0 0 100px #ff417d, 0 0 150px #ff417d;
  60.  
    }
  61.  
     
  62.  
    .title h1 span {
  63.  
    z-index: 99;
  64.  
    font-weight: 600;
  65.  
    padding: 0;
  66.  
    margin: 0;
  67.  
    color: #ffffff;
  68.  
    }
  69.  
     
  70.  
    .title h3 {
  71.  
    z-index: 99;
  72.  
    font-weight: 200;
  73.  
    font-size: 26px;
  74.  
    padding: 0;
  75.  
    margin: 0;
  76.  
    line-height: 1;
  77.  
    color: #ffffff;
  78.  
    letter-spacing: 2px;
  79.  
    }
  80.  
     
  81.  
    /* 爱心css */
  82.  
    canvas {
  83.  
    position: absolute;
  84.  
    width: 100%;
  85.  
    height: 100%;
  86.  
    }
  87.  
    .img {
  88.  
    position: absolute;
  89.  
    left: 50%;
  90.  
    top: 60%;
  91.  
    transform: translate(-50%, -50%);
  92.  
    width: 180px; /* 160 */
  93.  
    height: 180px;
  94.  
    }
  95.  
    #pinkboard {
  96.  
    position: relative;
  97.  
    top: 0%;
  98.  
    left: 0%;
  99.  
    height: 429px;
  100.  
    }
  101.  
    .STARDUST1 {
  102.  
    position: relative !important;
  103.  
    top: -60px;
  104.  
    }
  105.  
    .STARDUST2 {
  106.  
    position: relative !important;
  107.  
    top: -40px;
  108.  
    }
  109.  
    .STARDUST3 {
  110.  
    position: relative !important;
  111.  
    top: -20px;
  112.  
    }
  113.  
    /* 星空css */
  114.  
    html,
  115.  
    body {
  116.  
    padding: 0px;
  117.  
    margin: 0px;
  118.  
    width: 100%;
  119.  
    height: 100%;
  120.  
    position: fixed;
  121.  
    }
  122.  
     
  123.  
    body {
  124.  
    display: flex;
  125.  
    justify-content: center;
  126.  
    align-items: center;
  127.  
    -webkit-filter: contrast(120%);
  128.  
    filter: contrast(120%);
  129.  
    background-image: radial-gradient(
  130.  
    1600px at 70% 120%,
  131.  
    rgba(33, 39, 80, 1) 10%,
  132.  
    #020409 100%
  133.  
    ) !important;
  134.  
    /* background-color: black; */
  135.  
    }
  136.  
     
  137.  
    .container2 {
  138.  
    /* z-index: 8; */
  139.  
    position: absolute;
  140.  
    width: 100%;
  141.  
    height: 100%;
  142.  
    background-image: radial-gradient(
  143.  
    1600px at 70% 120%,
  144.  
    rgba(33, 39, 80, 1) 10%,
  145.  
    #020409 100%
  146.  
    ) !important;
  147.  
    }
  148.  
     
  149.  
    .content {
  150.  
    width: inherit;
  151.  
    height: inherit;
  152.  
    width: 100%;
  153.  
    height: 100%;
  154.  
    background-image: radial-gradient(
  155.  
    1600px at 70% 120%,
  156.  
    rgba(33, 39, 80, 1) 10%,
  157.  
    #020409 100%
  158.  
    ) !important;
  159.  
    }
  160.  
     
  161.  
    #universe {
  162.  
    width: 100%;
  163.  
    height: 100%;
  164.  
    }
  165.  
     
  166.  
    #footerContent {
  167.  
    font-family: sans-serif;
  168.  
    font-size: 110%;
  169.  
    color: rgba(200, 220, 255, 0.3);
  170.  
    width: 100%;
  171.  
    position: fixed;
  172.  
    bottom: 0px;
  173.  
    padding: 20px;
  174.  
    text-align: center;
  175.  
    z-index: 20;
  176.  
    }
  177.  
     
  178.  
    /* #footer {
  179.  
    position: absolute;
  180.  
    bottom: 0px;
  181.  
    height: 300px;
  182.  
    width: 100%;
  183.  
    } */
  184.  
     
  185.  
    #scene {
  186.  
    height: 100%;
  187.  
    position: absolute;
  188.  
    left: 50%;
  189.  
    margin-left: -800px;
  190.  
    }
  191.  
     
  192.  
    a {
  193.  
    text-decoration: none;
  194.  
    color: rgba(200, 220, 255, 1);
  195.  
    opacity: 0.4;
  196.  
    transition: opacity 0.4s ease;
  197.  
    }
  198.  
     
  199.  
    a:hover {
  200.  
    opacity: 1;
  201.  
    }
  202.  
    </style>
  203.  
     
  204.  
    </head>
  205.  
     
  206.  
    <body>
  207.  
    <audio autoplay="autopaly">
  208.  
    <source src="renxi.mp3" type="audio/mp3" />
  209.  
    </audio>
  210.  
    <!-- 星空html -->
  211.  
    <!-- <div> -->
  212.  
    <div class="container2">
  213.  
    <div class="content">
  214.  
    <canvas id="universe"></canvas>
  215.  
    </div>
  216.  
    </div>
  217.  
    <!-- </div> -->
  218.  
    <div class="title">
  219.  
    <!-- 星团文字html -->
  220.  
    <h3 class="STARDUST1">&nbsp;&nbsp;1999年6月6日 - 永远</h3>
  221.  
    <h1 class="STARDUST2">小花-相遇是缘</h1>
  222.  
    <h3 class="STARDUST3">L O V E <strong></strong> Y O U</h3>
  223.  
    <!-- 爱心html -->
  224.  
    <img class="img" src="Image/37.jpg" alt="" />
  225.  
    <canvas id="pinkboard"> </canvas>
  226.  
    </div>
  227.  
    </body>
  228.  
    <!-- 星团js -->
  229.  
    <script>
  230.  
    let particles = [];
  231.  
    let microparticles = [];
  232.  
     
  233.  
    const c1 = createCanvas({
  234.  
    width: $(window).width(),
  235.  
    height: $(window).height(),
  236.  
    });
  237.  
     
  238.  
    const tela = c1.canvas;
  239.  
    const canvas = c1.context;
  240.  
     
  241.  
    // $("body").append(tela);
  242.  
    $("body").append(c1.canvas);
  243.  
     
  244.  
    class Particle1 {
  245.  
    constructor(canvas) {
  246.  
    this.random = Math.random();
  247.  
    this.random1 = Math.random();
  248.  
    this.random2 = Math.random();
  249.  
    this.progress = 0;
  250.  
    this.canvas = canvas;
  251.  
    this.life = 1000 Math.random() * 3000;
  252.  
     
  253.  
    this.x =
  254.  
    $(window).width() / 2 (Math.random() * 20 - Math.random() * 20);
  255.  
    this.y = $(window).height();
  256.  
    this.s = 2 Math.random();
  257.  
    this.w = $(window).width();
  258.  
    this.h = $(window).height();
  259.  
    this.direction = this.random > 0.5 ? -1 : 1;
  260.  
    this.radius = 1 3 * this.random;
  261.  
    this.color = "#ff417d";
  262.  
     
  263.  
    this.ID = setInterval(
  264.  
    function () {
  265.  
    microparticles.push(
  266.  
    new microParticle(c1.context, {
  267.  
    x: this.x,
  268.  
    y: this.y,
  269.  
    })
  270.  
    );
  271.  
    }.bind(this),
  272.  
    this.random * 20
  273.  
    );
  274.  
     
  275.  
    setTimeout(
  276.  
    function () {
  277.  
    clearInterval(this.ID);
  278.  
    }.bind(this),
  279.  
    this.life
  280.  
    );
  281.  
    }
  282.  
     
  283.  
    render() {
  284.  
    this.canvas.beginPath();
  285.  
    this.canvas.arc(this.x, this.y, this.radius, 0, 2 * Math.PI);
  286.  
    // this.canvas.lineWidth = 2;
  287.  
    this.canvas.shadowOffsetX = 0;
  288.  
    this.canvas.shadowOffsetY = 0;
  289.  
    // this.canvas.shadowBlur = 6;
  290.  
    this.canvas.shadowColor = "#000000";
  291.  
    this.canvas.fillStyle = this.color;
  292.  
    this.canvas.fill();
  293.  
    this.canvas.closePath();
  294.  
    }
  295.  
     
  296.  
    move() {
  297.  
    this.x -=
  298.  
    this.direction *
  299.  
    Math.sin(this.progress / (this.random1 * 430)) *
  300.  
    this.s;
  301.  
    this.y -= Math.cos(this.progress / this.h) * this.s;
  302.  
     
  303.  
    if (this.x < 0 || this.x > this.w - this.radius) {
  304.  
    clearInterval(this.ID);
  305.  
    return false;
  306.  
    }
  307.  
     
  308.  
    if (this.y < 0) {
  309.  
    clearInterval(this.ID);
  310.  
    return false;
  311.  
    }
  312.  
    this.render();
  313.  
    this.progress ;
  314.  
    return true;
  315.  
    }
  316.  
    }
  317.  
     
  318.  
    class microParticle {
  319.  
    constructor(canvas, options) {
  320.  
    this.random = Math.random();
  321.  
    this.random1 = Math.random();
  322.  
    this.random2 = Math.random();
  323.  
    this.progress = 0;
  324.  
    this.canvas = canvas;
  325.  
     
  326.  
    this.x = options.x;
  327.  
    this.y = options.y;
  328.  
    this.s = 2 Math.random() * 3;
  329.  
    this.w = $(window).width();
  330.  
    this.h = $(window).height();
  331.  
    this.radius = 1 this.random * 0.5;
  332.  
    this.color = "#4EFCFE"; //this.random > .5 ? "#a9722c" : "#FFFED7"
  333.  
    }
  334.  
     
  335.  
    render() {
  336.  
    this.canvas.beginPath();
  337.  
    this.canvas.arc(this.x, this.y, this.radius, 0, 2 * Math.PI);
  338.  
    this.canvas.lineWidth = 2;
  339.  
    this.canvas.fillStyle = this.color;
  340.  
    this.canvas.fill();
  341.  
    this.canvas.closePath();
  342.  
    }
  343.  
     
  344.  
    move() {
  345.  
    this.x -=
  346.  
    Math.sin(this.progress / (100 / (this.random1 - this.random2 * 10))) *
  347.  
    this.s;
  348.  
    this.y = Math.cos(this.progress / this.h) * this.s;
  349.  
     
  350.  
    if (this.x < 0 || this.x > this.w - this.radius) {
  351.  
    return false;
  352.  
    }
  353.  
     
  354.  
    if (this.y > this.h) {
  355.  
    return false;
  356.  
    }
  357.  
    this.render();
  358.  
    this.progress ;
  359.  
    return true;
  360.  
    }
  361.  
    }
  362.  
     
  363.  
    var random_life = 1000;
  364.  
     
  365.  
    setInterval(
  366.  
    function () {
  367.  
    particles.push(new Particle1(canvas));
  368.  
    random_life = 2000 * Math.random();
  369.  
    }.bind(this),
  370.  
    random_life
  371.  
    );
  372.  
     
  373.  
    function clear() {
  374.  
    let grd = canvas.createRadialGradient(
  375.  
    tela.width / 2,
  376.  
    tela.height / 2,
  377.  
    0,
  378.  
    tela.width / 2,
  379.  
    tela.height / 2,
  380.  
    tela.width
  381.  
    );
  382.  
    grd.addColorStop(0, "rgba(20,20,20,1)");
  383.  
    grd.addColorStop(1, "rgba(0,0,0,0)");
  384.  
    // Fill with gradient
  385.  
    canvas.globalAlpha = 0.16;
  386.  
    canvas.fillStyle = grd;
  387.  
    canvas.fillRect(0, 0, tela.width, tela.height);
  388.  
    }
  389.  
     
  390.  
    function blur(ctx, canvas, amt) {
  391.  
    // ctx.filter = `blur(${amt}px)`
  392.  
    // ctx.drawImage(canvas, 0, 0)
  393.  
    // ctx.filter = 'none'
  394.  
    }
  395.  
     
  396.  
    function update() {
  397.  
    clear();
  398.  
    particles = particles.filter(function (p) {
  399.  
    return p.move();
  400.  
    });
  401.  
    microparticles = microparticles.filter(function (mp) {
  402.  
    return mp.move();
  403.  
    });
  404.  
    requestAnimationFrame(update.bind(this));
  405.  
    }
  406.  
     
  407.  
    function createCanvas(properties) {
  408.  
    let canvas = document.createElement("canvas");
  409.  
    canvas.width = properties.width;
  410.  
    // canvas.style.zIndex = 999;
  411.  
    canvas.height = properties.height;
  412.  
    let context = canvas.getContext("2d");
  413.  
    return {
  414.  
    canvas: canvas,
  415.  
    context: context,
  416.  
    };
  417.  
    }
  418.  
    update();
  419.  
    </script>
  420.  
    <!--爱心js -->
  421.  
    <script>
  422.  
    /*
  423.  
    * Settings
  424.  
    */
  425.  
    var settings = {
  426.  
    particles: {
  427.  
    length: 500, // maximum amount of particles
  428.  
    duration: 2, // particle duration in sec
  429.  
    velocity: 100, // particle velocity in pixels/sec
  430.  
    effect: -0.75, // play with this for a nice effect
  431.  
    size: 30, // particle size in pixels
  432.  
    },
  433.  
    };
  434.  
     
  435.  
    /*
  436.  
    * RequestAnimationFrame polyfill by Erik M?ller
  437.  
    */
  438.  
    (function () {
  439.  
    var b = 0;
  440.  
    var c = ["ms", "moz", "webkit", "o"];
  441.  
    for (var a = 0; a < c.length && !window.requestAnimationFrame; a) {
  442.  
    window.requestAnimationFrame = window[c[a] "RequestAnimationFrame"];
  443.  
    window.cancelAnimationFrame =
  444.  
    window[c[a] "CancelAnimationFrame"] ||
  445.  
    window[c[a] "CancelRequestAnimationFrame"];
  446.  
    }
  447.  
    if (!window.requestAnimationFrame) {
  448.  
    window.requestAnimationFrame = function (h, e) {
  449.  
    var d = new Date().getTime();
  450.  
    var f = Math.max(0, 16 - (d - b));
  451.  
    var g = window.setTimeout(function () {
  452.  
    h(d f);
  453.  
    }, f);
  454.  
    b = d f;
  455.  
    return g;
  456.  
    };
  457.  
    }
  458.  
    if (!window.cancelAnimationFrame) {
  459.  
    window.cancelAnimationFrame = function (d) {
  460.  
    clearTimeout(d);
  461.  
    };
  462.  
    }
  463.  
    })();
  464.  
     
  465.  
    /*
  466.  
    * Point class
  467.  
    */
  468.  
    var Point = (function () {
  469.  
    function Point(x, y) {
  470.  
    this.x = typeof x !== "undefined" ? x : 0;
  471.  
    this.y = typeof y !== "undefined" ? y : 0;
  472.  
    }
  473.  
    Point.prototype.clone = function () {
  474.  
    return new Point(this.x, this.y);
  475.  
    };
  476.  
    Point.prototype.length = function (length) {
  477.  
    if (typeof length == "undefined")
  478.  
    return Math.sqrt(this.x * this.x this.y * this.y);
  479.  
    this.normalize();
  480.  
    this.x *= length;
  481.  
    this.y *= length;
  482.  
    return this;
  483.  
    };
  484.  
    Point.prototype.normalize = function () {
  485.  
    var length = this.length();
  486.  
    this.x /= length;
  487.  
    this.y /= length;
  488.  
    return this;
  489.  
    };
  490.  
    return Point;
  491.  
    })();
  492.  
     
  493.  
    /*
  494.  
    * Particle class
  495.  
    */
  496.  
    var Particle = (function () {
  497.  
    function Particle() {
  498.  
    this.position = new Point();
  499.  
    this.velocity = new Point();
  500.  
    this.acceleration = new Point();
  501.  
    this.age = 0;
  502.  
    }
  503.  
    Particle.prototype.initialize = function (x, y, dx, dy) {
  504.  
    this.position.x = x;
  505.  
    this.position.y = y;
  506.  
    this.velocity.x = dx;
  507.  
    this.velocity.y = dy;
  508.  
    this.acceleration.x = dx * settings.particles.effect;
  509.  
    this.acceleration.y = dy * settings.particles.effect;
  510.  
    this.age = 0;
  511.  
    };
  512.  
    Particle.prototype.update = function (deltaTime) {
  513.  
    this.position.x = this.velocity.x * deltaTime;
  514.  
    this.position.y = this.velocity.y * deltaTime;
  515.  
    this.velocity.x = this.acceleration.x * deltaTime;
  516.  
    this.velocity.y = this.acceleration.y * deltaTime;
  517.  
    this.age = deltaTime;
  518.  
    };
  519.  
    Particle.prototype.draw = function (context, image) {
  520.  
    function ease(t) {
  521.  
    return --t * t * t 1;
  522.  
    }
  523.  
    var size = image.width * ease(this.age / settings.particles.duration);
  524.  
    context.globalAlpha = 1 - this.age / settings.particles.duration;
  525.  
    context.drawImage(
  526.  
    image,
  527.  
    this.position.x - size / 2,
  528.  
    this.position.y - size / 2,
  529.  
    size,
  530.  
    size
  531.  
    );
  532.  
    };
  533.  
    return Particle;
  534.  
    })();
  535.  
     
  536.  
    /*
  537.  
    * ParticlePool class
  538.  
    */
  539.  
    var ParticlePool = (function () {
  540.  
    var particles,
  541.  
    firstActive = 0,
  542.  
    firstFree = 0,
  543.  
    duration = settings.particles.duration;
  544.  
     
  545.  
    function ParticlePool(length) {
  546.  
    // create and populate particle pool
  547.  
    particles = new Array(length);
  548.  
    for (var i = 0; i < particles.length; i )
  549.  
    particles[i] = new Particle();
  550.  
    }
  551.  
    ParticlePool.prototype.add = function (x, y, dx, dy) {
  552.  
    particles[firstFree].initialize(x, y, dx, dy);
  553.  
     
  554.  
    // handle circular queue
  555.  
    firstFree ;
  556.  
    if (firstFree == particles.length) firstFree = 0;
  557.  
    if (firstActive == firstFree) firstActive ;
  558.  
    if (firstActive == particles.length) firstActive = 0;
  559.  
    };
  560.  
    ParticlePool.prototype.update = function (deltaTime) {
  561.  
    var i;
  562.  
     
  563.  
    // update active particles
  564.  
    if (firstActive < firstFree) {
  565.  
    for (i = firstActive; i < firstFree; i )
  566.  
    particles[i].update(deltaTime);
  567.  
    }
  568.  
    if (firstFree < firstActive) {
  569.  
    for (i = firstActive; i < particles.length; i )
  570.  
    particles[i].update(deltaTime);
  571.  
    for (i = 0; i < firstFree; i ) particles[i].update(deltaTime);
  572.  
    }
  573.  
     
  574.  
    // remove inactive particles
  575.  
    while (
  576.  
    particles[firstActive].age >= duration &&
  577.  
    firstActive != firstFree
  578.  
    ) {
  579.  
    firstActive ;
  580.  
    if (firstActive == particles.length) firstActive = 0;
  581.  
    }
  582.  
    };
  583.  
    ParticlePool.prototype.draw = function (context, image) {
  584.  
    // draw active particles
  585.  
    if (firstActive < firstFree) {
  586.  
    for (i = firstActive; i < firstFree; i )
  587.  
    particles[i].draw(context, image);
  588.  
    }
  589.  
    if (firstFree < firstActive) {
  590.  
    for (i = firstActive; i < particles.length; i )
  591.  
    particles[i].draw(context, image);
  592.  
    for (i = 0; i < firstFree; i ) particles[i].draw(context, image);
  593.  
    }
  594.  
    };
  595.  
    return ParticlePool;
  596.  
    })();
  597.  
     
  598.  
    /*
  599.  
    * Putting it all together
  600.  
    */
  601.  
    (function (canvas) {
  602.  
    var context = canvas.getContext("2d"),
  603.  
    particles = new ParticlePool(settings.particles.length),
  604.  
    particleRate = settings.particles.length / settings.particles.duration, // particles/sec
  605.  
    time;
  606.  
     
  607.  
    // get point on heart with -PI <= t <= PI
  608.  
    function pointOnHeart(t) {
  609.  
    return new Point(
  610.  
    160 * Math.pow(Math.sin(t), 3),
  611.  
    130 * Math.cos(t) -
  612.  
    50 * Math.cos(2 * t) -
  613.  
    20 * Math.cos(3 * t) -
  614.  
    10 * Math.cos(4 * t)
  615.  
    25
  616.  
    );
  617.  
    }
  618.  
     
  619.  
    // creating the particle image using a dummy canvas
  620.  
    var image = (function () {
  621.  
    var canvas = document.createElement("canvas"),
  622.  
    context = canvas.getContext("2d");
  623.  
    canvas.width = settings.particles.size;
  624.  
    canvas.height = settings.particles.size;
  625.  
    // helper function to create the path
  626.  
    function to(t) {
  627.  
    var point = pointOnHeart(t);
  628.  
    point.x =
  629.  
    settings.particles.size / 2
  630.  
    (point.x * settings.particles.size) / 350;
  631.  
    point.y =
  632.  
    settings.particles.size / 2 -
  633.  
    (point.y * settings.particles.size) / 350;
  634.  
    return point;
  635.  
    }
  636.  
    // create the path
  637.  
    context.beginPath();
  638.  
    var t = -Math.PI;
  639.  
    var point = to(t);
  640.  
    context.moveTo(point.x, point.y);
  641.  
    while (t < Math.PI) {
  642.  
    t = 0.01; // baby steps!
  643.  
    point = to(t);
  644.  
    context.lineTo(point.x, point.y);
  645.  
    }
  646.  
    context.closePath();
  647.  
    // create the fill
  648.  
    context.fillStyle = "#ea80b0";
  649.  
    context.fill();
  650.  
    // create the image
  651.  
    var image = new Image();
  652.  
    image.src = canvas.toDataURL();
  653.  
    return image;
  654.  
    })();
  655.  
     
  656.  
    // render that thing!
  657.  
    function render() {
  658.  
    // next animation frame
  659.  
    requestAnimationFrame(render);
  660.  
     
  661.  
    // update time
  662.  
    var newTime = new Date().getTime() / 1000,
  663.  
    deltaTime = newTime - (time || newTime);
  664.  
    time = newTime;
  665.  
     
  666.  
    // clear canvas
  667.  
    context.clearRect(0, 0, canvas.width, canvas.height);
  668.  
     
  669.  
    // create new particles
  670.  
    var amount = particleRate * deltaTime;
  671.  
    for (var i = 0; i < amount; i ) {
  672.  
    var pos = pointOnHeart(Math.PI - 2 * Math.PI * Math.random());
  673.  
    var dir = pos.clone().length(settings.particles.velocity);
  674.  
    particles.add(
  675.  
    canvas.width / 2 pos.x,
  676.  
    canvas.height / 2 - pos.y,
  677.  
    dir.x,
  678.  
    -dir.y
  679.  
    );
  680.  
    }
  681.  
     
  682.  
    // update and draw particles
  683.  
    particles.update(deltaTime);
  684.  
    particles.draw(context, image);
  685.  
    }
  686.  
     
  687.  
    // handle (re-)sizing of the canvas
  688.  
    function onResize() {
  689.  
    canvas.width = canvas.clientWidth;
  690.  
    canvas.height = canvas.clientHeight;
  691.  
    }
  692.  
    window.onresize = onResize;
  693.  
     
  694.  
    // delay rendering bootstrap
  695.  
    setTimeout(function () {
  696.  
    onResize();
  697.  
    render();
  698.  
    }, 10);
  699.  
    })(document.getElementById("pinkboard"));
  700.  
    </script>
  701.  
     
  702.  
    <!-- 星空js -->
  703.  
    <script>
  704.  
    window.requestAnimationFrame =
  705.  
    window.requestAnimationFrame ||
  706.  
    window.mozRequestAnimationFrame ||
  707.  
    window.webkitRequestAnimationFrame ||
  708.  
    window.msRequestAnimationFrame;
  709.  
     
  710.  
    var starDensity = 0.216;
  711.  
    var speedCoeff = 0.05;
  712.  
    var width;
  713.  
    var height;
  714.  
    var starCount;
  715.  
    var circleRadius;
  716.  
    var circleCenter;
  717.  
    var first = true;
  718.  
    var giantColor = "180,184,240";
  719.  
    var starColor = "226,225,142";
  720.  
    var cometColor = "226,225,224";
  721.  
    var canva = document.getElementById("universe");
  722.  
    canva.style.zIndex = 200;
  723.  
    var stars = [];
  724.  
     
  725.  
    windowResizeHandler();
  726.  
    window.addEventListener("resize", windowResizeHandler, false);
  727.  
     
  728.  
    createUniverse();
  729.  
     
  730.  
    function createUniverse() {
  731.  
    universe = canva.getContext("2d");
  732.  
     
  733.  
    for (var i = 0; i < starCount; i ) {
  734.  
    stars[i] = new Star();
  735.  
    stars[i].reset();
  736.  
    }
  737.  
     
  738.  
    draw();
  739.  
    }
  740.  
     
  741.  
    function draw() {
  742.  
    universe.clearRect(0, 0, width, height);
  743.  
     
  744.  
    var starsLength = stars.length;
  745.  
     
  746.  
    for (var i = 0; i < starsLength; i ) {
  747.  
    var star = stars[i];
  748.  
    star.move();
  749.  
    star.fadeIn();
  750.  
    star.fadeOut();
  751.  
    star.draw();
  752.  
    }
  753.  
     
  754.  
    window.requestAnimationFrame(draw);
  755.  
    }
  756.  
     
  757.  
    function Star() {
  758.  
    this.reset = function () {
  759.  
    this.giant = getProbability(3);
  760.  
    this.comet = this.giant || first ? false : getProbability(10);
  761.  
    this.x = getRandInterval(0, width - 10);
  762.  
    this.y = getRandInterval(0, height);
  763.  
    this.r = getRandInterval(1.1, 2.6);
  764.  
    this.dx =
  765.  
    getRandInterval(speedCoeff, 6 * speedCoeff)
  766.  
    (this.comet 1 - 1) * speedCoeff * getRandInterval(50, 120)
  767.  
    speedCoeff * 2;
  768.  
    this.dy =
  769.  
    -getRandInterval(speedCoeff, 6 * speedCoeff) -
  770.  
    (this.comet 1 - 1) * speedCoeff * getRandInterval(50, 120);
  771.  
    this.fadingOut = null;
  772.  
    this.fadingIn = true;
  773.  
    this.opacity = 0;
  774.  
    this.opacityTresh = getRandInterval(
  775.  
    0.2,
  776.  
    1 - (this.comet 1 - 1) * 0.4
  777.  
    );
  778.  
    this.do = getRandInterval(0.0005, 0.002) (this.comet 1 - 1) * 0.001;
  779.  
    };
  780.  
     
  781.  
    this.fadeIn = function () {
  782.  
    if (this.fadingIn) {
  783.  
    this.fadingIn = this.opacity > this.opacityTresh ? false : true;
  784.  
    this.opacity = this.do;
  785.  
    }
  786.  
    };
  787.  
     
  788.  
    this.fadeOut = function () {
  789.  
    if (this.fadingOut) {
  790.  
    this.fadingOut = this.opacity < 0 ? false : true;
  791.  
    this.opacity -= this.do / 2;
  792.  
    if (this.x > width || this.y < 0) {
  793.  
    this.fadingOut = false;
  794.  
    this.reset();
  795.  
    }
  796.  
    }
  797.  
    };
  798.  
     
  799.  
    this.draw = function () {
  800.  
    universe.beginPath();
  801.  
     
  802.  
    if (this.giant) {
  803.  
    universe.fillStyle = "rgba(" giantColor "," this.opacity ")";
  804.  
    universe.arc(this.x, this.y, 2, 0, 2 * Math.PI, false);
  805.  
    } else if (this.comet) {
  806.  
    universe.fillStyle = "rgba(" cometColor "," this.opacity ")";
  807.  
    universe.arc(this.x, this.y, 1.5, 0, 2 * Math.PI, false);
  808.  
     
  809.  
    //comet tail
  810.  
    for (var i = 0; i < 30; i ) {
  811.  
    universe.fillStyle =
  812.  
    "rgba("
  813.  
    cometColor
  814.  
    ","
  815.  
    (this.opacity - (this.opacity / 20) * i)
  816.  
    ")";
  817.  
    universe.rect(
  818.  
    this.x - (this.dx / 4) * i,
  819.  
    this.y - (this.dy / 4) * i - 2,
  820.  
    2,
  821.  
    2
  822.  
    );
  823.  
    universe.fill();
  824.  
    }
  825.  
    } else {
  826.  
    universe.fillStyle = "rgba(" starColor "," this.opacity ")";
  827.  
    universe.rect(this.x, this.y, this.r, this.r);
  828.  
    }
  829.  
     
  830.  
    universe.closePath();
  831.  
    universe.fill();
  832.  
    };
  833.  
     
  834.  
    this.move = function () {
  835.  
    this.x = this.dx;
  836.  
    this.y = this.dy;
  837.  
    if (this.fadingOut === false) {
  838.  
    this.reset();
  839.  
    }
  840.  
    if (this.x > width - width / 4 || this.y < 0) {
  841.  
    this.fadingOut = true;
  842.  
    }
  843.  
    };
  844.  
     
  845.  
    (function () {
  846.  
    setTimeout(function () {
  847.  
    first = false;
  848.  
    }, 50);
  849.  
    })();
  850.  
    }
  851.  
     
  852.  
    function getProbability(percents) {
  853.  
    return Math.floor(Math.random() * 1000) 1 < percents * 10;
  854.  
    }
  855.  
     
  856.  
    function getRandInterval(min, max) {
  857.  
    return Math.random() * (max - min) min;
  858.  
    }
  859.  
     
  860.  
    function windowResizeHandler() {
  861.  
    width = window.innerWidth;
  862.  
    height = window.innerHeight;
  863.  
    starCount = width * starDensity;
  864.  
    circleRadius = width > height ? height / 2 : width / 2;
  865.  
    circleCenter = {
  866.  
    x: width / 2,
  867.  
    y: height / 2,
  868.  
    };
  869.  
     
  870.  
    canva.setAttribute("width", width);
  871.  
    canva.setAttribute("height", height);
  872.  
    }
  873.  
    </script>
  874.  
    </html>
学新通

二、运行效果

学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgffcif
系列文章
更多 icon
同类精品
更多 icon
继续加载