整合營(yíng)銷服務(wù)商

          電腦端+手機(jī)端+微信端=數(shù)據(jù)同步管理

          免費(fèi)咨詢熱線:

          css - animation 常用的動(dòng)畫效果

          近項(xiàng)目需要,寫一些動(dòng)畫效果,下面對(duì)animation的知識(shí)鞏固了一下,希望可以幫助到有需要的小伙伴們。

          animation

          animation-name 需要綁定到選擇器的 keyframe 名稱


          animation-duration 完成動(dòng)畫所需要的時(shí)間


          animation-delay 設(shè)置延長(zhǎng)時(shí)間


          animation-timing-function 動(dòng)畫的運(yùn)動(dòng)速度


          • linear 動(dòng)畫從頭到尾的速度是相同的。
          • ease 默認(rèn)。動(dòng)畫以低速開始,然后加快,在結(jié)束前變慢。
          • ease-in 動(dòng)畫以低速開始。
          • ease-out 動(dòng)畫以低速結(jié)束。
          • ease-in-out 動(dòng)畫以低速開始和結(jié)束。
          • cubic-bezier(n,n,n,n) 在 cubic-bezier 函數(shù)中自己的值??赡艿闹凳菑?0 到 1 的數(shù)值。

          animation-iteration-count 動(dòng)畫播放的次數(shù)


          infinite 規(guī)定動(dòng)畫應(yīng)該無限次播放。

          animation-direction 輪流反向播放動(dòng)畫


          • normal 默認(rèn)值。動(dòng)畫應(yīng)該正常播放。
          • alternate 動(dòng)畫應(yīng)該輪流反向播放。

          這個(gè)先介紹到這里吧,下面分享幾個(gè)demo!!!

          1、animation1


          <div class="spinner">
           <div class="rect1"></div>
           <div class="rect2"></div>
           <div class="rect3"></div>
           <div class="rect4"></div>
           <div class="rect5"></div>
          </div>
          <style>
          .spinner {
           margin: 100px auto;
           width: 50px;
           height: 60px;
           text-align: center;
           font-size: 10px;
          }
           
          .spinner > div {
           background-color: #67CF22;
           height: 100%;
           width: 6px;
           display: inline-block;
           
           -webkit-animation: stretchdelay 1.2s infinite ease-in-out;
           animation: stretchdelay 1.2s infinite ease-in-out;
          }
           
          .spinner .rect2 {
           -webkit-animation-delay: -1.1s;
           animation-delay: -1.1s;
          }
           
          .spinner .rect3 {
           -webkit-animation-delay: -1.0s;
           animation-delay: -1.0s;
          }
           
          .spinner .rect4 {
           -webkit-animation-delay: -0.9s;
           animation-delay: -0.9s;
          }
           
          .spinner .rect5 {
           -webkit-animation-delay: -0.8s;
           animation-delay: -0.8s;
          }
           
          @-webkit-keyframes stretchdelay {
           0%, 40%, 100% { -webkit-transform: scaleY(0.4) } 
           20% { -webkit-transform: scaleY(1.0) }
          }
           
          @keyframes stretchdelay {
           0%, 40%, 100% {
           transform: scaleY(0.4);
           -webkit-transform: scaleY(0.4);
           } 20% {
           transform: scaleY(1.0);
           -webkit-transform: scaleY(1.0);
           }
          }
          </style>
          
          <div class="spinner"></div>
          <style>
          .spinner {
           width: 60px;
           height: 60px;
           background-color: #67CF22;
           
           margin: 100px auto;
           -webkit-animation: rotateplane 1.2s infinite ease-in-out;
           animation: rotateplane 1.2s infinite ease-in-out;
          }
           
          @-webkit-keyframes rotateplane {
           0% { -webkit-transform: perspective(120px) }
           50% { -webkit-transform: perspective(120px) rotateY(180deg) }
           100% { -webkit-transform: perspective(120px) rotateY(180deg) rotateX(180deg) }
          }
           
          @keyframes rotateplane {
           0% {
           transform: perspective(120px) rotateX(0deg) rotateY(0deg);
           -webkit-transform: perspective(120px) rotateX(0deg) rotateY(0deg)
           } 50% {
           transform: perspective(120px) rotateX(-180.1deg) rotateY(0deg);
           -webkit-transform: perspective(120px) rotateX(-180.1deg) rotateY(0deg)
           } 100% {
           transform: perspective(120px) rotateX(-180deg) rotateY(-179.9deg);
           -webkit-transform: perspective(120px) rotateX(-180deg) rotateY(-179.9deg);
           }
          }
          </style>
          
          <div class="spinner">
           <div class="double-bounce1"></div>
           <div class="double-bounce2"></div>
          </div>
          <style>
          .spinner {
           width: 60px;
           height: 60px;
           
           position: relative;
           margin: 100px auto;
          }
           
          .double-bounce1, .double-bounce2 {
           width: 100%;
           height: 100%;
           border-radius: 50%;
           background-color: #67CF22;
           opacity: 0.6;
           position: absolute;
           top: 0;
           left: 0;
           
           -webkit-animation: bounce 2.0s infinite ease-in-out;
           animation: bounce 2.0s infinite ease-in-out;
          }
           
          .double-bounce2 {
           -webkit-animation-delay: -1.0s;
           animation-delay: -1.0s;
          }
           
          @-webkit-keyframes bounce {
           0%, 100% { -webkit-transform: scale(0.0) }
           50% { -webkit-transform: scale(1.0) }
          }
           
          @keyframes bounce {
           0%, 100% {
           transform: scale(0.0);
           -webkit-transform: scale(0.0);
           } 50% {
           transform: scale(1.0);
           -webkit-transform: scale(1.0);
           }
          }
          </style>
          
          <div class="spinner">
           <div class="dot1"></div>
           <div class="dot2"></div>
          </div>
          <style>
          .spinner {
           margin: 100px auto;
           width: 90px;
           height: 90px;
           position: relative;
           text-align: center;
           
           -webkit-animation: rotate 2.0s infinite linear;
           animation: rotate 2.0s infinite linear;
          }
           
          .dot1, .dot2 {
           width: 60%;
           height: 60%;
           display: inline-block;
           position: absolute;
           top: 0;
           background-color: #67CF22;
           border-radius: 100%;
           
           -webkit-animation: bounce 2.0s infinite ease-in-out;
           animation: bounce 2.0s infinite ease-in-out;
          }
           
          .dot2 {
           top: auto;
           bottom: 0px;
           -webkit-animation-delay: -1.0s;
           animation-delay: -1.0s;
          }
           
          @-webkit-keyframes rotate { 100% { -webkit-transform: rotate(360deg) }}
          @keyframes rotate { 100% { transform: rotate(360deg); -webkit-transform: rotate(360deg) }}
           
          @-webkit-keyframes bounce {
           0%, 100% { -webkit-transform: scale(0.0) }
           50% { -webkit-transform: scale(1.0) }
          }
           
          @keyframes bounce {
           0%, 100% {
           transform: scale(0.0);
           -webkit-transform: scale(0.0);
           } 50% {
           transform: scale(1.0);
           -webkit-transform: scale(1.0);
           }
          }
          </style>
          
          <div class="spinner">
           <div class="bounce1"></div>
           <div class="bounce2"></div>
           <div class="bounce3"></div>
          </div>
          <style>
          .spinner {
           margin: 100px auto 0;
           width: 150px;
           text-align: center;
          }
           
          .spinner > div {
           width: 30px;
           height: 30px;
           background-color: #67CF22;
           
           border-radius: 100%;
           display: inline-block;
           -webkit-animation: bouncedelay 1.4s infinite ease-in-out;
           animation: bouncedelay 1.4s infinite ease-in-out;
           /* Prevent first frame from flickering when animation starts */
           -webkit-animation-fill-mode: both;
           animation-fill-mode: both;
          }
           
          .spinner .bounce1 {
           -webkit-animation-delay: -0.32s;
           animation-delay: -0.32s;
          }
           
          .spinner .bounce2 {
           -webkit-animation-delay: -0.16s;
           animation-delay: -0.16s;
          }
           
          @-webkit-keyframes bouncedelay {
           0%, 80%, 100% { -webkit-transform: scale(0.0) }
           40% { -webkit-transform: scale(1.0) }
          }
           
          @keyframes bouncedelay {
           0%, 80%, 100% {
           transform: scale(0.0);
           -webkit-transform: scale(0.0);
           } 40% {
           transform: scale(1.0);
           -webkit-transform: scale(1.0);
           }
          }
          </style>
          

          喜歡前端的小伙伴們可以在評(píng)論區(qū)留言,尋找和小馮童鞋一樣熱愛前端的友人,讓我們一起玩轉(zhuǎn)前端的世界!

          SS3 Animations

          1 @keyframes屬性

          @keyframes 動(dòng)畫名稱{關(guān)鍵幀持續(xù)時(shí)間% {css樣式;}}

          @keyframes myanimation
          {
              0% {top:0px;background-color:#0000cc;}
              50% {top:100px;background-color;#339900;}
              100% {top:0px;background-color:#330000;}
          }

          2 animation屬性

          animation: name duration timing-function delay iteration-count direction;

          animation-name 規(guī)定需要綁定到選擇器的 keyframe 名稱。。

          animation-duration 規(guī)定完成動(dòng)畫所花費(fèi)的時(shí)間, 以秒或毫秒計(jì)。

          animation-timing-function 規(guī)定動(dòng)畫的速度曲線。

          linear 動(dòng)畫從頭到尾的速度是相同的。

          ease 默認(rèn)。動(dòng)畫以低速開始, 然后加快, 在結(jié)束前變慢。

          ease-in 動(dòng)畫以低速開始。

          ease-out 動(dòng)畫以低速結(jié)束。

          ease-in-out 動(dòng)畫以低速開始和結(jié)束。

          cubic-bezier(n,n,n,n) 在 cubic-bezier 函數(shù)中自己的值??赡艿闹凳菑?0 到 1 的數(shù)值。 參考地址: http://cubic-bezier.com/#.17,.67,.83,.67

          animation-delay 規(guī)定在動(dòng)畫開始之前的延遲。以秒或毫秒計(jì), 默認(rèn)值是 0。

          animation-iteration-count 規(guī)定動(dòng)畫應(yīng)該播放的次數(shù)。

          n 定義動(dòng)畫播放次數(shù)的數(shù)值。

          infinite 規(guī)定動(dòng)畫應(yīng)該無限次播放。

          animation-direction 規(guī)定是否應(yīng)該輪流反向播放動(dòng)畫。

          normal 默認(rèn)值。動(dòng)畫應(yīng)該正常播放。

          alternate 動(dòng)畫應(yīng)該輪流反向播放。

          使用方法一: from...to...

          <!DOCTYPE html>
          <html>
          <head>
          <meta charset="UTF-8">
          <title></title>
          <style type="text/css">
          *{
              margin: 0;
              padding: 0;
          }
          div{
              width: 100px;
              height: 100px;
              background-color: orange;
          
          }
          
          /*div:hover{
          width: 800px;
          }*/
          /*@keyframes 動(dòng)畫名{
          from{
          動(dòng)畫第一步(這里你可以不寫他會(huì)繼承上面的)
          }
          to{
          動(dòng)畫最后一步
          }
          }*/
          /*動(dòng)畫聲明*/
          @keyframes widthChange{
          /*from{
          width: 100px;
          }*/
          to{
          width: 800px;
          }
          }
          div{
              /*animation: 動(dòng)畫名稱 過渡總時(shí)長(zhǎng);*/
              animation: widthChange 1s;
          }
          </style>
          </head>
          <body>
          <div></div>
          </body>
          </html>

          使用方法二: 百分比

          <!DOCTYPE html>
          <html>
          <head>
          <meta charset="UTF-8">
          <title></title>
          <style type="text/css">
          *{
          margin: 0;
          padding: 0;
          }
          div{
          width: 100px;
          height: 100px;
          background-color: orange;
          position: absolute;
          left: 0;
          top: 0;
          }
          
          /*動(dòng)畫聲明*/
          @keyframes positionChange{
              /*from{
              left: 0;
              }
              to{
              left: 800px;
              }*/
              /*百分?jǐn)?shù)評(píng)分的的過渡總時(shí)長(zhǎng)*/
              0%{
              left: 0;
              top: 0;
              }
              50%{
              left: 800px;
              top: 0;
              }
              100%{
              left: 800px;
              top: 500px;
              }
          }
          div{
              /*animation: 動(dòng)畫名稱 過渡總時(shí)長(zhǎng);*/
              animation: positionChange 10s;
          }
          </style>
          </head>
          <body>
          <div></div>
          </body>
          </html>

          使用方法三: animation參數(shù)格式

          <!DOCTYPE html>
          <html>
          <head>
          <meta charset="UTF-8">
          <title></title>
          <style type="text/css">
          *{
              margin: 0;
              padding: 0;
          }
          div{
              width: 100px;
              height: 100px;
              background-color: orange;
          
          }
          @keyframes widthChange{
              to{
              width: 800px;
              }
          }
          div{
              /*
              * 動(dòng)畫名稱
              * 動(dòng)畫總時(shí)長(zhǎng)s ms
              * 動(dòng)畫形式ease ease-in ease-out ease-in-out linear 貝塞爾曲線、
              * 延遲時(shí)間s ms
              * 循環(huán)次數(shù)①阿拉伯?dāng)?shù)字②infinite(無限次)
              * 停留到最后一幀forwards
              * 反向播放動(dòng)畫alternate(來回當(dāng)做2次處理) normal 正常
              *
              * */
              animation: widthChange 5s;
          }
          div:hover{
          /*動(dòng)畫停止*/
          animation-play-state: paused
          }
          </style>
          </head>
          <body>
          <div></div>
          </body>
          </html>

          建立3D場(chǎng)景

          transform-style 屬性規(guī)定如何在 3D 空間中呈現(xiàn)被嵌套的元素。

          注釋:該屬性必須與 transform 屬性一同使用。

          flat 子元素將不保留其 3D 位置。

          preserve-3d 子元素將保留其 3D 位置。

          transform-style: flat|preserve-3d;

          perspective 屬性定義 3D 元素距視圖的距離, 以像素計(jì)。該屬性允許您改變 3D 元素查看 3D 元素的視圖。

          當(dāng)為元素定義 perspective 屬性時(shí), 其子元素會(huì)獲得透視效果, 而不是元素本身。

          注釋:perspective 屬性只影響 3D 轉(zhuǎn)換元素。

          perspective: number|none;

          景深:

          perspective是設(shè)置3d效果的景深, 通俗來說就是設(shè)置你的眼睛與這個(gè)3d元素的距離。

          而生活經(jīng)驗(yàn)告訴我們, 你從遠(yuǎn)處和近處分別觀察同一個(gè)物體(比如正方形)時(shí), 其3d效果肯定是不同的。

          perspective-origin 屬性定義 3D 元素所基于的 X 軸和 Y 軸。該屬性允許您改變 3D 元素的底部位置。

          當(dāng)為元素定義 perspective-origin 屬性時(shí), 其子元素會(huì)獲得透視效果, 而不是元素本身。

          注釋:該屬性必須與 perspective 屬性一同使用, 而且只影響 3D 轉(zhuǎn)換元素。

          <!DOCTYPE html>
          <html lang="zh">
          <head>
          <meta charset="UTF-8" />
          <meta name="viewport" content="width=device-width, initial-scale=1.0" />
          <meta http-equiv="X-UA-Compatible" content="ie=edge" />
          <title>Document</title>
          <style type="text/css">
          *{
              margin: 0;
              padding: 0;
              list-style: none;
          }
          div{
              width: 300px;
              height: 220px;
              margin: 100px auto;
              border: 1px solid #000;
          
              transform-style: preserve-3d;
              perspective: 800px;
          
              /*景深基點(diǎn)基本上沒人改*/
              perspective-origin: left top;
          }
          img{
              width: 100%;
              display: block;
              transition: 1s;
              }
              div:hover>img{
              transform: rotateX(-45deg);
          }
          </style>
          </head>
          <body>
          <div>
          <img src="img/薛凱琪.jpg"/>
          </div>
          </body>
          </html>

          backface-visibility 屬性定義當(dāng)元素不面向屏幕時(shí)是否可見。

          如果在旋轉(zhuǎn)元素不希望看到其背面時(shí), 該屬性很有用。

          背面隱藏

          言:每當(dāng)過節(jié)的時(shí)候,女朋友就抱怨我總是忘記給她買花,說程序不懂浪漫,這不我準(zhǔn)備了幾款愛心動(dòng)畫特效,打算當(dāng)面向她表達(dá)一下。

          第一款:html5通過canvas實(shí)現(xiàn)浪漫告白愛心動(dòng)畫特效

          寓意:告白無須多么華麗的語言,一顆顆小的愛心匯聚成一顆真心,讓你的另一半感受到濃濃的愛意。

          代碼難度系數(shù)★★★

          新建index.html,復(fù)制以下代碼保存在瀏覽器中打開即可。

          <!doctype html>
          <html>
          <head>
          <meta charset="utf-8">
          <title>canvas 心</title>
          
          <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>
          

          第二款:html5通過canvas實(shí)現(xiàn)愛心氣球上升動(dòng)畫特效

          寓意:將想說的話打開一顆顆的愛心氣球上,隨著氣球不斷的升空,讓整個(gè)氛圍可更加地纏綿,看到此處可以有感動(dòng)的淚水。

          代碼難度系數(shù)★★★

          新建index.html,復(fù)制以下代碼保存在瀏覽器中打開即可。

          <!doctype html>
          <html>
          <head>
          <meta charset="utf-8">
          <title>情人節(jié)快樂:)</title>
          
          <style>
          canvas {
          	position: absolute;
          	top: 0;
          	left: 0;
          }</style>
          </head>
          <body>
          <canvas id=c></canvas>
          
          <script>
          var w = c.width = window.innerWidth,
          		h = c.height = window.innerHeight,
          		ctx = c.getContext( '2d' ),
          		
          		opts = {
          			phrases: [ "Don't die\nit's not hard", "You're the Best", "Every day,\nYou're beautiful", "Every occasion,\nYou're clever", "A world without You?\nNah", "Keep kicking ass", "You're better than them,\nwhoever they are", "You're just amazing", "You are,\ntherefore I am", "Nothing better than You \ncould have happened to the world" ],
          			balloons: 10,
          			baseVelY: -1,
          			addedVelY: -1,
          			baseVelX: -.25,
          			addedVelX: .5,
          			baseSize: 20,
          			addedSize: 10,
          			baseSizeAdder: 2,
          			addedSizeAdder: 2,
          			baseIncrementer: .01,
          			addedIncrementer: .03,
          			baseHue: -10,
          			addedHue: 30,
          			font: '15px Verdana'
          		},
          		
          		cycle = 0,
          		balloons = [];
          
          ctx.font = opts.font;
          
          function Balloon(){
          	this.reset();
          }
          Balloon.prototype.reset = function(){
          	
          	this.size = opts.baseSize + opts.addedSize * Math.random();
          	this.sizeAdder = opts.baseSizeAdder + opts.addedSizeAdder * Math.random();
          	this.incrementer = opts.baseIncrementer + opts.addedIncrementer * Math.random();
          	
          	this.tick = 0;
          	
          	this.x = Math.random() * w;
          	this.y = h + this.size;
          	
          	this.vx = opts.baseVelX + opts.addedVelX * Math.random();
          	this.vy = opts.baseVelY + opts.addedVelY * Math.random();
          	
          	this.color = 'hsla(hue,70%,60%,.8)'.replace( 'hue', opts.baseHue + opts.addedHue * Math.random() );
          	this.phrase = opts.phrases[ ++cycle % opts.phrases.length ].split( '\n' );
          	this.lengths = [];
          	
          	for( var i = 0; i < this.phrase.length; ++i )
          		this.lengths.push( -ctx.measureText( this.phrase[ i ] ).width / 2 );
          }
          Balloon.prototype.step = function(){
          	
          	this.tick += this.incrementer;
          	this.x += this.vx;
          	this.y += this.vy;
          	
          	var size = this.size + this.sizeAdder * Math.sin( this.tick );
          	
          	ctx.lineWidth = size / 40;
          	ctx.strokeStyle = '#eee';
          	ctx.beginPath();
          	ctx.moveTo( this.x, this.y - 2 );
          	ctx.lineTo( this.x, this.y + size );
          	ctx.stroke();
          	ctx.fillStyle = this.color;
          	
          	ctx.translate( this.x, this.y );
          	ctx.rotate( Math.PI / 4 );
          	//ctx.fillRect( -size / 2, -size / 2, size / 2, size / 2 );
          	ctx.beginPath();
          	ctx.moveTo( 0, 0 );
          	ctx.arc( -size / 2, -size / 2 + size / 4, size / 4, Math.PI / 2, Math.PI * 3 / 2 );
          	ctx.arc( -size / 2 + size / 4, -size / 2, size / 4, Math.PI, Math.PI * 2 );
          	ctx.lineTo( 0, 0 );
          	ctx.fill();
          	ctx.rotate( -Math.PI / 4 );
          	ctx.translate( -this.x, -this.y );
          	
          	ctx.translate( this.x, this.y + size + 15 );
          	ctx.scale( size / this.size, size / this.size );
          	ctx.fillStyle = '#eee';
          	for( var i = 0; i < this.phrase.length; ++i )
          		ctx.fillText( this.phrase[ i ], this.lengths[ i ], i * 15 );
          	ctx.scale( this.size / size, this.size / size );
          	ctx.translate( -this.x, -( this.y + size + 15 ) );
          	
          	if( this.y < -size * 3 )
          		this.reset();
          	
          }
          
          function anim(){
          	
          	window.requestAnimationFrame( anim );
          	
          	ctx.fillStyle = '#222';
          	ctx.fillRect( 0, 0, w, h );
          	
          	if( balloons.length < opts.balloons && Math.random() < .01 )
          		balloons.push( new Balloon );
          	
          	for( var i = 0; i < balloons.length; ++i )
          		balloons[ i ].step();
          }
          anim();</script>
          
          </body>
          </html>
          

          第三款:jQuery+css3實(shí)現(xiàn)愛心雨動(dòng)畫特效

          寓意:天空中下起了愛心雨,襯托的房間變得溫暖,也讓整個(gè)場(chǎng)景都變得溫馨無比,想必此時(shí)可以有一個(gè)大大的擁抱。

          代碼難度系數(shù)★★★

          代碼有image、js和html,所以不好貼出來,有需要的朋友直接問我要吧。

          總結(jié):程序員的工作本身就很枯燥,特定找了幾個(gè)好看的特效拿出來和大家分享,希望大家能夠快樂每一天,上述代碼親測(cè)可用,歡迎點(diǎn)贊收藏。

          《完》

          大家如果喜歡的話麻煩點(diǎn)贊、關(guān)注、轉(zhuǎn)發(fā),謝謝大家。


          主站蜘蛛池模板: 国产人妖视频一区二区破除| 久久精品无码一区二区三区日韩| 精品女同一区二区三区免费站| 久久99国产一区二区三区| 午夜爽爽性刺激一区二区视频| 国产一区中文字幕在线观看| 国产精品被窝福利一区| 精品国产福利第一区二区三区| 麻豆AV一区二区三区久久| 亚洲日本va一区二区三区| 国产一区二区在线视频播放| 国产日韩精品一区二区三区在线 | 成人免费一区二区无码视频 | 国产精品无码一区二区三区在| 一区二区三区无码高清| 伊人色综合一区二区三区| 一区二区三区在线观看| 武侠古典一区二区三区中文| 日韩AV无码一区二区三区不卡毛片 | 78成人精品电影在线播放日韩精品电影一区亚洲 | 国产在线一区二区| 无码少妇一区二区浪潮免费| 国产精品污WWW一区二区三区| 国产乱码一区二区三区四| 一区二区国产精品| 国产香蕉一区二区在线网站 | 久久亚洲日韩精品一区二区三区| 精品日韩一区二区| 亚洲国产一区在线| 国产精品一区在线观看你懂的| 国产精品亚洲午夜一区二区三区| 国产在线观看一区精品| 国模视频一区二区| 99久久精品日本一区二区免费| 99精品高清视频一区二区| 国产成人午夜精品一区二区三区| 无码少妇精品一区二区免费动态| 日本一区二区在线免费观看| 少妇人妻精品一区二区| 激情内射亚洲一区二区三区爱妻| 一区二区三区中文|