我是一个人的博客

我是一个人,只是一个人

网站&HTML-页面特效

网站 HTML 0 评 154 度

有时候我们有一些特殊需要,比如现在是公祭日,我们要用灰白的页面,比如我想用下雪的或者灯笼过节了,等等,本篇文章主要就写了这些东西。

复制粘贴代码使,也可以自己修改一下,都是我挑过的。本文是我当作备忘录写的,所以有一些是我网上扒的成品,看着玩吧

CSS动画,就是通过CSS (Cascading Style Sheet) 代码搭建网页动画。允许设计师和开发人员,通过编辑网站的CSS代码来添加页面动画,从而轻松取代传统动画图片或flash动画的设计方式。

如此,设计师和开发人员就可简单通过粘贴复制CSS代码,快速复用其动画设计,轻松提高网站兼容性的同时,提升网页加载速度。

其他特效

https://juejin.cn/post/7172535582206197797

https://cloud.tencent.com/developer/article/1665353

全页特效

1.下雪css 原文

1

<script type="text/javascript">
       window.onload = function () {
                    var minSize = 5; //最小字体
                    var maxSize = 50;//最大字体
                    var newOne = 100; //生成雪花间隔
                    var flakColor = "#fff"; //雪花颜色
                    var flak = $("<div></div>").css({position:"absolute","top":"0px"}).html("❉");//定义一个雪花
                    var dhight = $(window).height(); //定义视图高度
                    var dw =$(window).width()-80; //定义视图宽度
                    setInterval(function(){
                    var sizeflak = minSize+Math.random()*maxSize; //产生大小不等的雪花
                    var startLeft = Math.random()*dw; //雪花生成是随机的left值
                    var startOpacity = 0.7+Math.random()*0.3; //随机透明度
                    var endTop= dhight-100; //雪花停止top的位置
                    var endLeft= Math.random()*dw; //雪花停止的left位置
                    var durationfull = 5000+Math.random()*5000; //雪花飘落速度不同
                    flak.clone().appendTo($("body")).css({
                    "left":startLeft ,
                    "opacity":startOpacity,
                    "font-size":sizeflak,
                    "color":flakColor
                    }).animate({
                    "top":endTop,
                    "left":endLeft,
                    "apacity":0.1
                    },durationfull,function(){
                    $(this).remove()
                    });
                    },newOne);
                }
</script>

2

  <script type="text/javascript">
       /* 控制下雪 */
       function snowFall(snow) {
           /* 可配置属性 */
           snow = snow || {};
           this.maxFlake = snow.maxFlake || 200;   /* 最多片数 */
           this.flakeSize = snow.flakeSize || 10;  /* 雪花形状 */
           this.fallSpeed = snow.fallSpeed || 1;   /* 坠落速度 */
     }
      /* 兼容写法 */
      requestAnimationFrame = window.requestAnimationFrame ||
          window.mozRequestAnimationFrame ||
          window.webkitRequestAnimationFrame ||
          window.msRequestAnimationFrame ||
          window.oRequestAnimationFrame ||
          function(callback) { setTimeout(callback, 1000 / 60); };
  
      cancelAnimationFrame = window.cancelAnimationFrame ||
          window.mozCancelAnimationFrame ||
          window.webkitCancelAnimationFrame ||
          window.msCancelAnimationFrame ||
          window.oCancelAnimationFrame;
      /* 开始下雪 */
      snowFall.prototype.start = function(){
          /* 创建画布 */
          snowCanvas.apply(this);
          /* 创建雪花形状 */
          createFlakes.apply(this);
          /* 画雪 */
          drawSnow.apply(this)
      }
      /* 创建画布 */
      function snowCanvas() {
          /* 添加Dom结点 */
          var snowcanvas = document.createElement("canvas");
          snowcanvas.id = "snowfall";
          snowcanvas.width = window.innerWidth;
          snowcanvas.height = document.body.clientHeight;
          snowcanvas.setAttribute("style", "position:absolute; top: 0; left: 0; z-index: 1; pointer-events: none;");
          document.getElementsByTagName("body")[0].appendChild(snowcanvas);
          this.canvas = snowcanvas;
          this.ctx = snowcanvas.getContext("2d");
          /* 窗口大小改变的处理 */
          window.onresize = function() {
              snowcanvas.width = window.innerWidth;
              /* snowcanvas.height = window.innerHeight */
          }
      }
      /* 雪运动对象 */
      function flakeMove(canvasWidth, canvasHeight, flakeSize, fallSpeed) {
          this.x = Math.floor(Math.random() * canvasWidth);   /* x坐标 */
          this.y = Math.floor(Math.random() * canvasHeight);  /* y坐标 */
          this.size = Math.random() * flakeSize + 2;          /* 形状 */
          this.maxSize = flakeSize;                           /* 最大形状 */
          this.speed = Math.random() * 1 + fallSpeed;         /* 坠落速度 */
          this.fallSpeed = fallSpeed;                         /* 坠落速度 */
          this.velY = this.speed;                             /* Y方向速度 */
          this.velX = 0;                                      /* X方向速度 */
          this.stepSize = Math.random() / 30;                 /* 步长 */
          this.step = 0                                       /* 步数 */
      }
      flakeMove.prototype.update = function() {
          var x = this.x,
              y = this.y;
          /* 左右摆动(余弦) */
          this.velX *= 0.98;
          if (this.velY <= this.speed) {
              this.velY = this.speed
          }
          this.velX += Math.cos(this.step += .05) * this.stepSize;
  
          this.y += this.velY;
          this.x += this.velX;
          /* 飞出边界的处理 */
          if (this.x >= canvas.width || this.x <= 0 || this.y >= canvas.height || this.y <= 0) {
              this.reset(canvas.width, canvas.height)
          }
      };
      /* 飞出边界-放置最顶端继续坠落 */
      flakeMove.prototype.reset = function(width, height) {
          this.x = Math.floor(Math.random() * width);
          this.y = 0;
          this.size = Math.random() * this.maxSize + 2;
          this.speed = Math.random() * 1 + this.fallSpeed;
          this.velY = this.speed;
          this.velX = 0;
      };
      // 渲染雪花-随机形状(此处可修改雪花颜色!!!)
      flakeMove.prototype.render = function(ctx) {
          var snowFlake = ctx.createRadialGradient(this.x, this.y, 0, this.x, this.y, this.size);
          snowFlake.addColorStop(0, "rgba(255, 255, 255, 0.9)");  /* 此处是雪花颜色,默认是白色 */
          snowFlake.addColorStop(.5, "rgba(255, 255, 255, 0.5)"); /* 若要改为其他颜色,请自行查 */
          snowFlake.addColorStop(1, "rgba(255, 255, 255, 0)");    /* 找16进制的RGB 颜色代码。 */
          ctx.save();
          ctx.fillStyle = snowFlake;
          ctx.beginPath();
          ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
          ctx.fill();
          ctx.restore();
     };
     /* 创建雪花-定义形状 */
     function createFlakes() {
         var maxFlake = this.maxFlake,
             flakes = this.flakes = [],
             canvas = this.canvas;
         for (var i = 0; i < maxFlake; i++) {
             flakes.push(new flakeMove(canvas.width, canvas.height, this.flakeSize, this.fallSpeed))
         }
     }
     /* 画雪 */
     function drawSnow() {
         var maxFlake = this.maxFlake,
             flakes = this.flakes;
         ctx = this.ctx, canvas = this.canvas, that = this;
         /* 清空雪花 */
         ctx.clearRect(0, 0, canvas.width, canvas.height);
         for (var e = 0; e < maxFlake; e++) {
             flakes[e].update();
             flakes[e].render(ctx);
         }
         /*  一帧一帧的画 */
         this.loop = requestAnimationFrame(function() {
             drawSnow.apply(that);
         });
     }
     /* 调用及控制方法 */
     var snow = new snowFall({maxFlake:60});
     snow.start();
 </script>

3

<script type="text/javascript">
       /* 控制下雪 */
       function snowFall(snow) {
           /* 可配置属性 */
           snow = snow || {};
           this.maxFlake = snow.maxFlake || 200;   /* 最多片数 */
           this.flakeSize = snow.flakeSize || 10;  /* 雪花形状 */
           this.fallSpeed = snow.fallSpeed || 1;   /* 坠落速度 */
     }
      /* 兼容写法 */
      requestAnimationFrame = window.requestAnimationFrame ||
          window.mozRequestAnimationFrame ||
          window.webkitRequestAnimationFrame ||
          window.msRequestAnimationFrame ||
          window.oRequestAnimationFrame ||
          function(callback) { setTimeout(callback, 1000 / 60); };
  
      cancelAnimationFrame = window.cancelAnimationFrame ||
          window.mozCancelAnimationFrame ||
          window.webkitCancelAnimationFrame ||
          window.msCancelAnimationFrame ||
          window.oCancelAnimationFrame;
      /* 开始下雪 */
      snowFall.prototype.start = function(){
          /* 创建画布 */
          snowCanvas.apply(this);
          /* 创建雪花形状 */
          createFlakes.apply(this);
          /* 画雪 */
          drawSnow.apply(this)
      }
      /* 创建画布 */
      function snowCanvas() {
          /* 添加Dom结点 */
          var snowcanvas = document.createElement("canvas");
          snowcanvas.id = "snowfall";
          snowcanvas.width = window.innerWidth;
          snowcanvas.height = document.body.clientHeight;
          snowcanvas.setAttribute("style", "position:absolute; top: 0; left: 0; z-index: 1; pointer-events: none;");
          document.getElementsByTagName("body")[0].appendChild(snowcanvas);
          this.canvas = snowcanvas;
          this.ctx = snowcanvas.getContext("2d");
          /* 窗口大小改变的处理 */
          window.onresize = function() {
              snowcanvas.width = window.innerWidth;
              /* snowcanvas.height = window.innerHeight */
          }
      }
      /* 雪运动对象 */
      function flakeMove(canvasWidth, canvasHeight, flakeSize, fallSpeed) {
          this.x = Math.floor(Math.random() * canvasWidth);   /* x坐标 */
          this.y = Math.floor(Math.random() * canvasHeight);  /* y坐标 */
          this.size = Math.random() * flakeSize + 2;          /* 形状 */
          this.maxSize = flakeSize;                           /* 最大形状 */
          this.speed = Math.random() * 1 + fallSpeed;         /* 坠落速度 */
          this.fallSpeed = fallSpeed;                         /* 坠落速度 */
          this.velY = this.speed;                             /* Y方向速度 */
          this.velX = 0;                                      /* X方向速度 */
          this.stepSize = Math.random() / 30;                 /* 步长 */
          this.step = 0                                       /* 步数 */
      }
      flakeMove.prototype.update = function() {
          var x = this.x,
              y = this.y;
          /* 左右摆动(余弦) */
          this.velX *= 0.98;
          if (this.velY <= this.speed) {
              this.velY = this.speed
          }
          this.velX += Math.cos(this.step += .05) * this.stepSize;
  
          this.y += this.velY;
          this.x += this.velX;
          /* 飞出边界的处理 */
          if (this.x >= canvas.width || this.x <= 0 || this.y >= canvas.height || this.y <= 0) {
              this.reset(canvas.width, canvas.height)
          }
      };
      /* 飞出边界-放置最顶端继续坠落 */
      flakeMove.prototype.reset = function(width, height) {
          this.x = Math.floor(Math.random() * width);
          this.y = 0;
          this.size = Math.random() * this.maxSize + 2;
          this.speed = Math.random() * 1 + this.fallSpeed;
          this.velY = this.speed;
          this.velX = 0;
      };
      // 渲染雪花-随机形状(此处可修改雪花颜色!!!)
      flakeMove.prototype.render = function(ctx) {
          var snowFlake = ctx.createRadialGradient(this.x, this.y, 0, this.x, this.y, this.size);
          snowFlake.addColorStop(0, "rgba(255, 255, 255, 0.9)");  /* 此处是雪花颜色,默认是白色 */
          snowFlake.addColorStop(.5, "rgba(255, 255, 255, 0.5)"); /* 若要改为其他颜色,请自行查 */
          snowFlake.addColorStop(1, "rgba(255, 255, 255, 0)");    /* 找16进制的RGB 颜色代码。 */
          ctx.save();
          ctx.fillStyle = snowFlake;
          ctx.beginPath();
          ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
          ctx.fill();
          ctx.restore();
     };
     /* 创建雪花-定义形状 */
     function createFlakes() {
         var maxFlake = this.maxFlake,
             flakes = this.flakes = [],
             canvas = this.canvas;
         for (var i = 0; i < maxFlake; i++) {
             flakes.push(new flakeMove(canvas.width, canvas.height, this.flakeSize, this.fallSpeed))
         }
     }
     /* 画雪 */
     function drawSnow() {
         var maxFlake = this.maxFlake,
             flakes = this.flakes;
         ctx = this.ctx, canvas = this.canvas, that = this;
         /* 清空雪花 */
         ctx.clearRect(0, 0, canvas.width, canvas.height);
         for (var e = 0; e < maxFlake; e++) {
             flakes[e].update();
             flakes[e].render(ctx);
         }
         /*  一帧一帧的画 */
         this.loop = requestAnimationFrame(function() {
             drawSnow.apply(that);
         });
     }
     /* 调用及控制方法 */
     var snow = new snowFall({maxFlake:60});
     snow.start();
 </script>

  <script type="text/javascript">  
 (function($){  
    $.fn.snow = function(options){  
     var $flake = $('<div id="snowbox" />').css({'position': 'absolute','z-index':'9999', 'top': '-50px', 'cursor': 'pointer'}).html('❄'),  
     documentHeight  = $(document).height(),  
     documentWidth   = $(document).width(),  
     defaults = {  
         minSize     : 10,  
         maxSize     : 20,  
         newOn       : 1000,  
         flakeColor  : "#AFDAEF" /* 此处可以定义雪花颜色,若要白色可以改为#FFFFFF */  
     },  
     options = $.extend({}, defaults, options);  
     var interval= setInterval( function(){  
     var startPositionLeft = Math.random() * documentWidth - 100,  
     startOpacity = 0.5 + Math.random(),  
     sizeFlake = options.minSize + Math.random() * options.maxSize,  
     endPositionTop = documentHeight - 200,  
     endPositionLeft = startPositionLeft - 500 + Math.random() * 500,  
     durationFall = documentHeight * 10 + Math.random() * 5000;  
     $flake.clone().appendTo('body').css({  
         left: startPositionLeft,  
         opacity: startOpacity,  
         'font-size': sizeFlake,  
         color: options.flakeColor  
     }).animate({  
         top: endPositionTop,  
        left: endPositionLeft,  
         opacity: 0.2  
     },durationFall,'linear',function(){  
        $(this).remove()  
     });  
     }, options.newOn);  
     };  
 })(jQuery);  
 $(function(){  
     $.fn.snow({   
         minSize: 5, /* 定义雪花最小尺寸 */  
       maxSize: 50,/* 定义雪花最大尺寸 */  
         newOn: 300  /* 定义密集程度,数字越小越密集 */  
    });  
 });  
</script> 

2.灯笼 原文

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>CSS 实现灯笼动画</title>
  </head>
  <link rel="stylesheet" href="../common.css" />
  <style>
    :root {
      --lineColor: #ecaa2f;
      --bg: #f00;
    }
    .container {
      width: 200px;
      height: 150px;
      position: relative;
      animation: rotate 3s infinite ease-in-out;
    }
    .center {
      position: relative;
      width: 100%;
      height: 100%;
      background: var(--bg);
      border-radius: 120px;
      box-shadow: 0 0 80px -10px var(--bg);
      animation: rotate 3s infinite ease-in-out;
      transform-origin: top center;
    }
    .center::before {
      content: "";
      position: absolute;
      top: -8px;
      left: calc(50% - 40px);
      width: 80px;
      height: 10px;
      background: var(--lineColor);
      border-radius: 5px 5px 0 0;
      z-index: 2;
    }
    .center::after {
      content: "";
      width: 80px;
      height: 10px;
      background: var(--lineColor);
      border-radius: 0 0 5px 5px;
      position: absolute;
      bottom: -8px;
      left: calc(50% - 40px);
      z-index: 2;
    }
    .center-line {
      width: 100%;
      height: 100%;
    }
    .center-line span {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 18px;
      font-size: 18px;
      color: var(--lineColor);
      font-weight: bold;
    }
    .center-line::before {
      content: "";
      position: absolute;
      top: 0;
      left: calc(50% - 75px);
      width: 150px;
      height: 150px;
      border: 2px solid var(--lineColor);
      border-radius: 50%;
    }
    .center-line::after {
      content: "";
      position: absolute;
      top: 0;
      left: calc(50% - 35px);
      width: 70px;
      height: 150px;
      border: 2px solid var(--lineColor);
      border-radius: 50%;
    }
    .head-line {
      position: absolute;
      left: calc(50% - 2px);
      top: -60px;
      width: 4px;
      height: 60px;
      background-color: var(--lineColor);
    }
    .footer-line {
      position: absolute;
      left: calc(50% - 2px);
      bottom: -50px;
      width: 4px;
      height: 50px;
      background-color: var(--lineColor);
      animation: rotate 3s infinite ease-in-out;
    }
    .footer-line::after {
      content: "";
      position: absolute;
      bottom: -75px;
      left: calc(50% - 8px);
      width: 16px;
      height: 80px;
      background: linear-gradient(
        #f00,
        #e36d00 3px,
        #fbd342 5px,
        #e36d00 8px,
        #e36d00 12px,
        #f00 16px,
        rgba(255, 0, 0, 0.8) 26px,
        rgba(255, 0, 0, 0.6)
      );
      border-radius: 5px 5px 0 0;
    }
    @keyframes rotate {
      0%,
      100% {
        transform: rotate(-10deg);
      }
      50% {
        transform: rotate(10deg);
      }
    }
  </style>
  <body>
    <div class="container">
      <span class="head-line"></span>
      <div class="center">
        <div class="center-line">
          <span>节日快乐</span>
        </div>
        <span class="footer-line"></span>
      </div>
    </div>
  </body>
</html>

3.灰白-国家公祭日

body {
        -webkit-filter: grayscale(1); /* Chrome, Safari, Opera */
        filter: grayscale(1);
}

网站&HTML/CSS/PHP/Js/SQL&VPS服务器-网站建设指南 序言
快来做第一个评论的人吧~