html--瀑布结果

打印 上一主题 下一主题

主题 517|帖子 517|积分 1551

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>瀑布效果</title>
  6. <style>
  7. body {
  8.   background: #222;
  9.   color: white;
  10.   overflow:hidden;
  11. }
  12. #container {
  13.   box-shadow: inset 0 1px 0 #444, 0 -1px 0 #000;
  14.   height: 100vh;
  15.   width: 100vw;
  16.   position: absolute;
  17.   left: 0;
  18.   top: 0;
  19.   margin: 0;
  20.   will-change: transform;
  21.   -webkit-transform: translateZ(0);
  22.           transform: translateZ(0);
  23. }
  24. canvas#waterfall {
  25.   display: block;
  26.   margin: 0 auto;
  27.   width: 30%;
  28.   height: 55%;
  29.   will-change: transform;
  30.   -webkit-transform: translateZ(0);
  31.           transform: translateZ(0);
  32. }
  33. .emma {
  34.   height: 100vh;
  35.   width: 100%;
  36.   position: absolute;
  37.   left: 0;
  38.   top: 0;
  39.   margin: 0;
  40. }
  41. h1 {
  42.   color: #0af;
  43.   font-size: 30vw;
  44. }
  45. canvas#surface {
  46.   -webkit-animation: fade-in 3000ms forwards;
  47.           animation: fade-in 3000ms forwards;
  48.   display: block;
  49.   left: 0;
  50.   position: absolute;
  51.   top: 0;
  52.   z-index: -1;
  53. }
  54. @-webkit-keyframes fade-in {
  55.   0% {
  56.     opacity: 0;
  57.   }
  58.   100% {
  59.     opacity: 1;
  60.   }
  61. }
  62. @keyframes fade-in {
  63.   0% {
  64.     opacity: 0;
  65.   }
  66.   100% {
  67.     opacity: 1;
  68.   }
  69. }
  70. </style>
  71. </head>
  72. <body>
  73. <div id="container">
  74.         <canvas id="waterfall"></canvas>
  75.        
  76.     <div class="emma flex">
  77.         <div> </div>
  78.     </div>
  79.        
  80. </div>
  81. <script type="text/javascript" src="js/pixi.min.js"></script>
  82. <script type="text/javascript" src="js/tinycolor.min.js"></script>
  83. <script type="text/javascript">
  84. +!~-(function(PIXI, window, document, undefined) {
  85.   var waterfallCanvas = function(c, cw, ch) {
  86.     var _this = this;
  87.     this.c = c;
  88.     this.ctx = c.getContext('2d');
  89.     this.cw = cw;
  90.     this.ch = ch;
  91.     this.particles = [];
  92.     this.particleRate = 6;
  93.     this.gravity = 0.15;
  94.     this.init = function() {
  95.       this.loop();
  96.     };
  97.     this.reset = function() {
  98.       this.ctx.clearRect(0, 0, this.cw, this.ch);
  99.       this.particles = [];
  100.     };
  101.     this.rand = function(rMi, rMa) {
  102.       return ~~((Math.random() * (rMa - rMi + 1)) + rMi);
  103.     };
  104.     this.Particle = function() {
  105.       var newWidth = _this.rand(1, 20);
  106.       var newHeight = _this.rand(1, 45);
  107.       this.x = _this.rand(10 + (newWidth / 2), _this.cw - 10 - (newWidth / 2));
  108.       this.y = -newHeight;
  109.       this.vx = 0;
  110.       this.vy = 0;
  111.       this.width = newWidth;
  112.       this.height = newHeight;
  113.       this.hue = _this.rand(200, 220);
  114.       this.saturation = _this.rand(30, 60);
  115.       this.lightness = _this.rand(30, 60);
  116.     };
  117.     this.Particle.prototype.update = function(i) {
  118.       this.vx += this.vx;
  119.       this.vy += _this.gravity;
  120.       this.x += this.vx;
  121.       this.y += this.vy;
  122.     };
  123.     this.Particle.prototype.render = function() {
  124.       _this.ctx.strokeStyle = 'hsla(' + this.hue + ', ' + this.saturation + '%, ' + this.lightness + '%, .05)';
  125.       _this.ctx.beginPath();
  126.       _this.ctx.moveTo(this.x, this.y);
  127.       _this.ctx.lineTo(this.x, this.y + this.height);
  128.       _this.ctx.lineWidth = this.width / 2;
  129.       _this.ctx.lineCap = 'round';
  130.       _this.ctx.stroke();
  131.     };
  132.     this.Particle.prototype.renderBubble = function() {
  133.       _this.ctx.fillStyle = 'hsla(' + this.hue + ', 40%, 40%, 1)';
  134.       _this.ctx.fillStyle = 'hsla(' + this.hue + ', ' + this.saturation + '%, ' + this.lightness + '%, .3)';
  135.       _this.ctx.beginPath();
  136.       _this.ctx.arc(this.x + this.width / 2, _this.ch - 20 - _this.rand(0, 10), _this.rand(1, 8), 0, Math.PI * 2, false);
  137.       _this.ctx.fill();
  138.     };
  139.     this.createParticles = function() {
  140.       var i = this.particleRate;
  141.       while (i--) {
  142.         this.particles.push(new this.Particle());
  143.       }
  144.     };
  145.     this.removeParticles = function() {
  146.       var i = this.particleRate;
  147.       while (i--) {
  148.         var p = this.particles[i];
  149.         if (p.y > _this.ch - 20 - p.height) {
  150.           p.renderBubble();
  151.           _this.particles.splice(i, 1);
  152.         }
  153.       }
  154.     };
  155.     this.updateParticles = function() {
  156.       var i = this.particles.length;
  157.       while (i--) {
  158.         var p = this.particles[i];
  159.         p.update(i);
  160.       }
  161.     };
  162.     this.renderParticles = function() {
  163.       var i = this.particles.length;
  164.       while (i--) {
  165.         var p = this.particles[i];
  166.         p.render();
  167.       }
  168.     };
  169.     this.clearCanvas = function() {
  170.       this.ctx.globalCompositeOperation = 'destination-out';
  171.       this.ctx.fillStyle = 'rgba(255,255,255,.06)';
  172.       this.ctx.fillRect(0, 0, this.cw, this.ch);
  173.       this.ctx.globalCompositeOperation = 'lighter';
  174.     };
  175.     this.loop = function() {
  176.       var loopIt = function() {
  177.         requestAnimationFrame(loopIt, _this.c);
  178.         _this.clearCanvas();
  179.         _this.createParticles();
  180.         _this.updateParticles();
  181.         _this.renderParticles();
  182.         _this.removeParticles();
  183.       };
  184.       loopIt();
  185.     };
  186.   };
  187.   var isCanvasSupported = function() {
  188.     var elem = document.createElement('canvas');
  189.     return !!(elem.getContext && elem.getContext('2d'));
  190.   };
  191.   var setupRAF = function() {
  192.     var lastTime = 0;
  193.     var vendors = ['ms', 'moz', 'webkit', 'o'];
  194.     for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
  195.       window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
  196.       window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame'];
  197.     }
  198.     if (!window.requestAnimationFrame) {
  199.       window.requestAnimationFrame = function(callback, element) {
  200.         var currTime = new Date().getTime();
  201.         var timeToCall = Math.max(0, 16 - (currTime - lastTime));
  202.         var id = window.setTimeout(function() {
  203.           callback(currTime + timeToCall);
  204.         }, timeToCall);
  205.         lastTime = currTime + timeToCall;
  206.         return id;
  207.       };
  208.     }
  209.     if (!window.cancelAnimationFrame) {
  210.       window.cancelAnimationFrame = function(id) {
  211.         clearTimeout(id);
  212.       };
  213.     }
  214.   };
  215.   if (isCanvasSupported()) {
  216.     var c = document.getElementById('waterfall');
  217.     var cw = c.width = Math.max(document.getElementById('waterfall').scrollWidth, document.getElementById('waterfall').offsetWidth, document.getElementById('waterfall').clientWidth, document.getElementById('waterfall').scrollWidth, document.getElementById('waterfall').offsetWidth);
  218.     var ch = c.height = Math.max(document.getElementById('waterfall').scrollHeight, document.getElementById('waterfall').offsetHeight, document.getElementById('waterfall').clientHeight, document.getElementById('waterfall').scrollHeight, document.getElementById('waterfall').offsetHeight);
  219.     var waterfall = new waterfallCanvas(c, cw, ch);
  220.     setupRAF();
  221.     waterfall.init();
  222.   } /* Second plugin */
  223.   var w, h, renderer, stage, waveGraphics, partGraphics, waveTexture, partTexture, waveCount, partCount, waves, parts;
  224.   function init() {
  225.     renderer = PIXI.autoDetectRenderer(window.innerWidth, window.innerHeight / 2, {
  226.       backgroundColor: '0x' + tinycolor('hsl(200, 50%, 10%)').toHex()
  227.     });
  228.     stage = new PIXI.Container();
  229.     waveCount = 2000;
  230.     partCount = 1000;
  231.     waves = [];
  232.     parts = [];
  233.     document.body.appendChild(renderer.view);
  234.     reset();
  235.     for (var i = 0; i < 300; i++) {
  236.       step();
  237.     }
  238.     loop();
  239.   }
  240.   function reset() {
  241.     w = window.innerWidth;
  242.     h = window.innerHeight;
  243.     renderer.resize(w, h);
  244.     waveGraphics = null;
  245.     waveTexture = null;
  246.     partGraphics = null;
  247.     partTexture = null;
  248.     waveGraphics = new PIXI.Graphics();
  249.     waveGraphics.cacheAsBitmap = true;
  250.     waveGraphics.beginFill('0x' + tinycolor('hsl(200, 74%, 40%)').toHex(), 0.15);
  251.     waveGraphics.drawCircle(0, 0, 20);
  252.     waveGraphics.endFill();
  253.     waveTexture = waveGraphics.generateTexture();
  254.     partGraphics = new PIXI.Graphics();
  255.     partGraphics.cacheAsBitmap = true;
  256.     partGraphics.beginFill('0x' + tinycolor('hsl(200, 70%, 40%)').toHex(), 0.2);
  257.     partGraphics.drawCircle(0, 0, 15);
  258.     partGraphics.endFill();
  259.     partTexture = partGraphics.generateTexture();
  260.   }
  261.   function step() {
  262.     if (waves.length < waveCount) {
  263.       for (var i = 0; i < 10; i++) {
  264.         var wave = new PIXI.Sprite(waveTexture),
  265.           scale = 0.2 + Math.random() * 0.8;
  266.         wave.position.x = w / 2;
  267.         wave.position.y = h / 2;
  268.         wave.anchor.x = 0.5;
  269.         wave.anchor.y = 0.5;
  270.         wave.scale.x = scale * 10;
  271.         wave.scale.y = scale * 0.5;
  272.         wave.blendMode = PIXI.BLEND_MODES.SCREEN;
  273.         waves.push({
  274.           sprite: wave,
  275.           x: wave.position.x,
  276.           y: wave.position.y,
  277.           vx: 0,
  278.           vy: 0,
  279.           angle: Math.PI / 2 + Math.random() * Math.PI + Math.PI * 1.5,
  280.           speed: 0.01 + Math.random() / 10
  281.         });
  282.         stage.addChild(wave);
  283.       }
  284.     }
  285.     for (var i = 0, length = waves.length; i < length; i++) {
  286.       var wave = waves[i];
  287.       wave.sprite.position.x = wave.x;
  288.       wave.sprite.position.y = wave.y;
  289.       wave.vx = Math.cos(wave.angle) * wave.speed;
  290.       wave.vy = Math.sin(wave.angle) * wave.speed;
  291.       wave.x += wave.vx;
  292.       wave.y += wave.vy;
  293.       wave.speed *= 1.01;
  294.       if (wave.x > w + 200 || wave.x < -200 || wave.y > h + 200) {
  295.         wave.x = w / 2;
  296.         wave.y = h / 2;
  297.         wave.speed = 0.01 + Math.random() / 10;
  298.       }
  299.     }
  300.     if (parts.length < partCount) {
  301.       var part = new PIXI.Sprite(partTexture),
  302.         scale = 0.2 + Math.random() * 0.8,
  303.         type = Math.random() > 0.5 ? 1 : 0;
  304.       part.position.x = w / 2 + Math.random() * 380 - 190;
  305.       part.position.y = h / 2 + 0;
  306.       part.anchor.x = 0.5;
  307.       part.anchor.y = 0.5;
  308.       part.scale.x = type ? scale : scale * 0.5;
  309.       part.scale.y = type ? scale : scale * 15;
  310.       part.blendMode = PIXI.BLEND_MODES.SCREEN;
  311.       parts.push({
  312.         sprite: part,
  313.         ox: part.position.x,
  314.         oy: part.position.y,
  315.         x: part.position.x,
  316.         y: part.position.y,
  317.         vx: 0,
  318.         vy: 0,
  319.         angle: (-Math.PI * 0.5) + (w / 2 - part.position.x) / 750,
  320.         speed: 0.0001 + Math.random() / 50
  321.       });
  322.       stage.addChild(part);
  323.     }
  324.     for (var i = 0, length = parts.length; i < length; i++) {
  325.       var part = parts[i];
  326.       part.sprite.position.x = part.x;
  327.       part.sprite.position.y = part.y;
  328.       part.vx = Math.cos(part.angle) * part.speed;
  329.       part.vy = Math.sin(part.angle) * part.speed;
  330.       part.x += part.vx;
  331.       part.y += part.vy;
  332.       part.speed *= 1.01;
  333.       if (part.x > w + 50 || part.x < -50 || part.y < -50) {
  334.         part.x = part.ox;
  335.         part.y = part.oy;
  336.         part.speed = 0.01 + Math.random() / 50;
  337.       }
  338.     }
  339.     renderer.render(stage);
  340.   }
  341.   function loop() {
  342.     step();
  343.     requestAnimationFrame(loop);
  344.   }
  345.   window.addEventListener('resize', reset);
  346.   init();
  347. })(PIXI, this, document);
  348. </script>
  349. </body>
  350. </html>
复制代码




由于js文件过多,整个文件已放下载区,接待下载,free

下载链接:https://download.csdn.net/download/stqer/89289948

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

我爱普洱茶

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表