RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1266866
Accepted
Sevastopol'
Sevastopol'
Asked:2022-04-06 23:25:13 +0000 UTC2022-04-06 23:25:13 +0000 UTC 2022-04-06 23:25:13 +0000 UTC

一种颜色重叠另一种颜色的渐变动画

  • 772

以下线性渐变用作主要背景图像:

html, body, svg {margin: 0; padding: 0; width: 100%; height: 100vh;}
<svg id="svg">
<defs>
<linearGradient id="gradient">
<stop offset="0" stop-color="brown"/>
<stop offset="2" stop-color="chocolate"/>
</linearGradient>
</defs>
<rect x="0" y="0" width="100%" height="100vh" fill="url(#gradient)"/>

众所周知,渐变是从一种颜色到另一种颜色的平滑过渡。它们之间可以有多种颜色和过渡。在此示例中,仅使用了两种颜色 - 棕色和巧克力色。

我需要实现这个渐变的动画。您需要开始一个分离的垂直白色条带,该条带将从左向右移动,然后向相反方向移动。因此,从一个边缘移开,该条带将与它一起拉动渐变,从而以从一种颜色到白色的平滑过渡填充主背景。然后在相反的方向,用从另一种颜色到白色的平滑过渡填充主背景。

坡度

动画脚本:

  1. 垂直的白色条纹从左向右移动,以从棕色到白色的平滑过渡填充主背景;
  2. 一条垂直的白色条纹从右向左移动,以从巧克力色到白色的平滑过渡填充主背景;
  3. 动画正在循环播放。

这是此类动画最简单的场景。但是,如果可能的话,那么我想使这种情况复杂一点:

  1. 垂直的白色条纹从左向右移动,以从棕色到白色的平滑过渡填充主背景。在此动画期间,主背景图像被转换为​​顺时针方向的 360度旋转;
  2. 垂直的白色条纹从右向左移动,以从巧克力色到白色的平滑过渡填充主背景。在此动画期间,主背景图像转换为 360o逆时针旋转;
  3. 动画正在循环播放。

建议通过问题标签中指示的任何方式来实现这样的动画,即两者CSS,SMIL SVG和使用JavaScript(这可以是 Canvas - 使用编程语言 - JavaScript 的 HTML 元素)。

javascript
  • 5 5 个回答
  • 10 Views

5 个回答

  • Voted
  1. Best Answer
    Alexandr_TT
    2022-04-08T23:56:31Z2022-04-08T23:56:31Z

    在下面的所有示例中,gradientUnits="objectBoundingBox"这是默认值,因此,如果没有明确指定,gradientUnits="userSpaceOnUse"属性值将分别以百分比或分别为от 0 до 1 ,这意味着渐变会影响整个图形。

    我们将对渐变属性x1, x2, y1,的值进行动画处理y2

    #一。移动白色条纹,颜色从左到右扫过

    <svg width="300" height="300" version="1.1" xmlns="http://www.w3.org/2000/svg">
      <defs>
          <linearGradient id="Gradient" x1="0" x2="0" y1="0" y2="0">
             <animate attributeName="x2" values="0;1;1;0;0" keyTimes="0;.25;.5;.75;1"  dur="2s" repeatCount="indefinite" />  
             <stop offset="0%" stop-color="brown"/>
            <stop offset="50%" stop-color="white"/>
            <stop offset="100%" stop-color="chocolate"/>
          </linearGradient>
      </defs>
      <rect x="10" y="10" width="240" height="240" rx="25" fill="url(#Gradient)"/>
      
    </svg>

    #2。白条旋转

    <svg width="300" height="300" version="1.1" xmlns="http://www.w3.org/2000/svg">
      <defs>
          <linearGradient id="Gradient" x1="0" x2="0" y1="0" y2="1">
            <animate attributeName="x1" values="0;0;1;1;0" keyTimes="0;.25;.5;.75;1" dur="1s" repeatCount="indefinite" />
            <animate attributeName="y1" values="0;1;1;0;0" keyTimes="0;.25;.5;.75;1" dur="1s" repeatCount="indefinite" />
            <animate attributeName="x2" values="1;1;0;0;1" keyTimes="0;.25;.5;.75;1" dur="1s" repeatCount="indefinite" />
            <animate attributeName="y2" values="1;0;0;1;1" keyTimes="0;.25;.5;.75;1" dur="1s" repeatCount="indefinite" />
            <stop offset="0%" stop-color="brown"/>
            <stop offset="50%" stop-color="white"/>
            <stop offset="100%" stop-color="chocolate"/>
          </linearGradient>
      </defs>
      <rect x="10" y="10" width="240" height="240" rx="25" fill="url(#Gradient)"/>
      
    </svg>

    #3。白色条纹与星内其他颜色的旋转

    <svg xmlns="http://www.w3.org/2000/svg" width="475.07" height="475.07" viewBox="0 0 475.075 475.075" fill="#FFF">
    <defs>
          <linearGradient id="Gradient" x1="0" x2="0" y1="0" y2="1">
            <animate attributeName="x1" values="0;0;1;1;0" keyTimes="0;.25;.5;.75;1" dur="1.5s" repeatCount="indefinite" />
            <animate attributeName="y1" values="0;1;1;0;0" keyTimes="0;.25;.5;.75;1" dur="1.5s" repeatCount="indefinite" />
            <animate attributeName="x2" values="1;1;0;0;1" keyTimes="0;.25;.5;.75;1" dur="1.5s" repeatCount="indefinite" />
            <animate attributeName="y2" values="1;0;0;1;1" keyTimes="0;.25;.5;.75;1" dur="1.5s" repeatCount="indefinite" />
            <stop offset="0%" stop-color="red"/>
            <stop offset="50%" stop-color="white"/>
            <stop offset="100%" stop-color="blue"/>
          </linearGradient>
      </defs>
    <path fill="url(#Gradient)"  d="M324.63 288.5l20.55 120.2-107.63-56.82L129.6 408.7l20.86-120.2-87.37-84.8L183.57 186l53.95-109.06L291.5 186 412 203.7l-87.38 84.8z"/>
    </svg>

    #四。底部路径上的双星渐变旋转

    <svg xmlns="http://www.w3.org/2000/svg" width="475.07" height="475.07" viewBox="0 0 475.075 475.075" fill="#FFF">
    <defs>
    <linearGradient id="Lg" x1="0" x2="0" y1="0" y2="1">
            <animate attributeName="x1" values="0;0;1;1;0" keyTimes="0;.25;.5;.75;1" dur="1s" repeatCount="indefinite" />
            <animate attributeName="y1" values="0;1;1;0;0" keyTimes="0;.25;.5;.75;1" dur="1s" repeatCount="indefinite" />
            <animate attributeName="x2" values="1;1;0;0;1" keyTimes="0;.25;.5;.75;1" dur="1s" repeatCount="indefinite" />
            <animate attributeName="y2" values="1;0;0;1;1" keyTimes="0;.25;.5;.75;1" dur="1s" repeatCount="indefinite" />
            <stop offset="0%" stop-color="brown"/>
            <stop offset="50%" stop-color="white"/>
            <stop offset="100%" stop-color="chocolate"/>
          </linearGradient>
    </defs>   
    <path  fill="url(#Lg)" stroke="brown"   stroke-width="1" d="M475.07 186.57c0-7.04-5.32-11.42-16-13.13l-143.3-20.84-64.24-129.9c-3.62-7.8-8.28-11.7-14-11.7-5.7 0-10.36 3.9-13.98 11.7L159.3 152.6 16 173.44c-10.67 1.7-16 6.1-16 13.13 0 4 2.38 8.57 7.14 13.7l103.92 101.08L86.5 444.1c-.37 2.66-.56 4.57-.56 5.7 0 4 1 7.38 3 10.14 2 2.77 5 4.15 9 4.15 3.42 0 7.22-1.15 11.4-3.44l128.2-67.38 128.2 67.38c4 2.28 7.8 3.43 11.4 3.43 7.82 0 11.72-4.76 11.72-14.28 0-2.48-.1-4.38-.3-5.72l-24.54-142.74L467.66 200.3c4.94-4.97 7.4-9.54 7.4-13.73z"/>
        
        <path fill="brown" stroke="shocolate" stroke-width="2" d="M324.63 288.5l20.55 120.2-107.63-56.82L129.6 408.7l20.86-120.2-87.37-84.8L183.57 186l53.95-109.06L291.5 186 412 203.7l-87.38 84.8z"/>
    </svg>

    #5。双星不同,在不同轮廓上旋转渐变

    <svg xmlns="http://www.w3.org/2000/svg" width="475.07" height="475.07" viewBox="0 0 475.075 475.075" fill="#FFF">
    <defs>
    <linearGradient id="Lg1" x1="0" x2="0" y1="0" y2="1">
            <animate attributeName="x1" values="0;0;1;1;0" keyTimes="0;.25;.5;.75;1" dur="1s" repeatCount="indefinite" />
            <animate attributeName="y1" values="0;1;1;0;0" keyTimes="0;.25;.5;.75;1" dur="1s" repeatCount="indefinite" />
            <animate attributeName="x2" values="1;1;0;0;1" keyTimes="0;.25;.5;.75;1" dur="2s" repeatCount="indefinite" />
            <animate attributeName="y2" values="1;0;0;1;1" keyTimes="0;.25;.5;.75;1" dur="2s" repeatCount="indefinite" />
            <stop offset="0%" stop-color="brown"/>
            <stop offset="50%" stop-color="white"/>
            <stop offset="100%" stop-color="chocolate"/>
          </linearGradient> 
         <linearGradient id="Lg2" x1="0" x2="0" y1="0" y2="1">
            <animate attributeName="x1" values="0;0;1;1;0" keyTimes="0;.25;.5;.75;1" dur="1s" repeatCount="indefinite" />
            <animate attributeName="y1" values="0;1;1;0;0" keyTimes="0;.25;.5;.75;1" dur="1s" repeatCount="indefinite" />
            <animate attributeName="x2" values="1;1;0;0;1" keyTimes="0;.25;.5;.75;1" dur="1s" repeatCount="indefinite" />
            <animate attributeName="y2" values="1;0;0;1;1" keyTimes="0;.25;.5;.75;1" dur="1s" repeatCount="indefinite" />
            <stop offset="0%" stop-color="brown"/>
            <stop offset="50%" stop-color="white"/>
            <stop offset="100%" stop-color="crimson"/>
          </linearGradient> 
    </defs>   
    <path  fill="url(#Lg1)" stroke="black"  stroke-width="1" d="M475.07 186.57c0-7.04-5.32-11.42-16-13.13l-143.3-20.84-64.24-129.9c-3.62-7.8-8.28-11.7-14-11.7-5.7 0-10.36 3.9-13.98 11.7L159.3 152.6 16 173.44c-10.67 1.7-16 6.1-16 13.13 0 4 2.38 8.57 7.14 13.7l103.92 101.08L86.5 444.1c-.37 2.66-.56 4.57-.56 5.7 0 4 1 7.38 3 10.14 2 2.77 5 4.15 9 4.15 3.42 0 7.22-1.15 11.4-3.44l128.2-67.38 128.2 67.38c4 2.28 7.8 3.43 11.4 3.43 7.82 0 11.72-4.76 11.72-14.28 0-2.48-.1-4.38-.3-5.72l-24.54-142.74L467.66 200.3c4.94-4.97 7.4-9.54 7.4-13.73z"/>
        
        <path fill="url(#Lg2)" stroke="black" d="M324.63 288.5l20.55 120.2-107.63-56.82L129.6 408.7l20.86-120.2-87.37-84.8L183.57 186l53.95-109.06L291.5 186 412 203.7l-87.38 84.8z"/>
    </svg>

    在运行条后面进行颜色扫描的其他示例

    #一。水平从左到右和后退

    <style>
    .crc1 {
      fill: url('#Lg');
    }
    </style>
    <svg class="the-svg" width="100%" height="100%" viewBox="-20 -20 200 200">
      <circle class="crc1" cx="50" cy="50" r="50"  />
      <defs>
        <linearGradient id="Lg" x1="0" x2="0" y1="0" y2="0" gradientUnits="userSpaceOnUse">
          <stop offset="20%" stop-color="#24bed2"/>
          <stop offset="90%" stop-color="#FF00AE"/>
        <animate attributeName="x1" dur="4s" values="0;200;200;0" repeatCount="indefinite" />
        </linearGradient>
      </defs>
    </svg>

    #2。垂直颜色扫描

    <style>
    .crc1 {
      fill: url('#Lg');
    }
    </style>
    <svg class="the-svg" width="100%" height="100%" viewBox="-20 -20 200 200">
      <circle class="crc1" cx="50" cy="50" r="50"  />
      <defs>
        <linearGradient id="Lg" x1="0" x2="0" y1="0" y2="0" gradientUnits="userSpaceOnUse">
          <stop offset="20%" stop-color="#24bed2"/>
          <stop offset="90%" stop-color="#FF00AE"/>
        <animate attributeName="y1" dur="4s" values="0;200;200;0" repeatCount="indefinite" />
        </linearGradient>
      </defs>
    </svg>

    #3。在一个角度

    <style>
    .crc1 {
      fill: url('#Lg');
    }
    </style>
    <svg class="the-svg" width="100%" height="100%" viewBox="-10 -10 200 200">
      <circle class="crc1" cx="50" cy="50" r="50"  />
      <defs>
        <linearGradient id="Lg" x1="0" x2="0" y1="0" y2="0" gradientUnits="userSpaceOnUse">
          <stop offset="10%" stop-color="#24bed2"/>
          <stop offset="90%" stop-color="#FF00AE"/>
          <animate attributeName="x1" dur="5s" values="0;200;200;0" repeatCount="indefinite" />
          <animate attributeName="y1" dur="5s" values="0;200;200;0" repeatCount="indefinite" />
        </linearGradient>
      </defs>
    </svg>

    #4. 悬停时将一对颜色更改为另一对 (对我来说看起来很漂亮)

    <style>
    .crc1 {
      fill: url('#Lg');
    }
     .crc1 ~ defs stop {
      transition: 3s;
    }
    
    .crc1 ~ defs stop:first-child {
      stop-color: #24bed2;
    }
    .crc1:hover ~ defs stop:last-child {
      stop-color: #F4FFAF;
    } 
    </style>
    <svg class="the-svg" width="200px" height="200" viewBox="-10 -10 120 120">
      <circle class="crc1" cx="50" cy="50" r="50"  stroke="#F4FFAF"/>
      <defs>
        <linearGradient id="Lg" x1="0" x2="0" y1="90" y2="0" gradientUnits="userSpaceOnUse">
          <stop offset="2%" stop-color="#2C2C2C"/>
          <stop offset="50%" stop-color="#2C2C2C"/>
        </linearGradient>
      </defs>
    </svg>

    [奖金]

    使用渐变动画旋转三个环

    .container {
    width:50%;
    height:50%;
    }
    
    svg {
    background:black;
    }
    
    #path1 {
    fill:url(#gradl);
    stroke:none;
    fill-opacity:1;
    }
    #path2 {
    fill:url(#grad2);
    stroke:none;
    fill-opacity:0.8;
    }
    #crc1 {
    stroke:none;
    fill:black;
    }
    #txt1 {
    fill:url(#grad2);
    
    }
    <div class="container">
     
    <svg id="svg1" xmlns="http://www.w3.org/2000/svg"  xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"  viewBox="0 0 300 300" > 
    <defs>
            <linearGradient id="gradl" gradientUnits="objectBoundingBox" x1="0" y1="0" x2="1" y2="1">
                <stop offset="0%" stop-color="dodgerblue"> 
                 <animate attributeName="stop-color" dur="1.5s" values="dodgerblue;yellow;dodgerblue" repeatCount="indefinite" restart="whenNotActive" />   
                 </stop>             
                <stop offset="100%" stop-color="yellow">
               <animate attributeName="stop-color" dur="1.5s" values="yellow;dodgerblue;yellow" repeatCount="indefinite"  restart="whenNotActive" />    
                 </stop>                        
                
            </linearGradient> 
            <linearGradient id="grad2" gradientUnits="objectBoundingBox" x1="0" y1="0" x2="1" y2="1">
                <stop offset="0%" stop-color="lime">
                  <animate attributeName="stop-color" dur="1.5s" values="lime;purple;lime" repeatCount="indefinite" restart="whenNotActive" />  
                 </stop>                
                <stop offset="100%" stop-color="purple">
               <animate attributeName="stop-color" dur="1.5s" values="purple;lime;purple" repeatCount="indefinite" restart="whenNotActive"  />  
                 </stop>                
            </linearGradient>
        
            </defs>
    <path id="path1" d="M71.9 78.4C90.8 58.1 122.9 50.7 150.6 51.5c26.2 0.7 54.9 10.5 72.8 29.7 16.9 18.1 22.9 45.8 23.4 70.6 0.5 25.1-3.2 54.4-20.7 72.4-18.5 19.1-49.4 24.5-76 24.3-25.4-0.2-54.4-6.3-72.4-24.3C59.5 205.8 53.9 176.5 53 150.8 52.2 125.9 55 96.7 71.9 78.4Z" > 
     <animateTransform attributeName="transform" type="rotate" values="0 150 150;360 150 150" begin="svg1.click" dur="20s" restart="whenNotActive" /> 
    </path>
    
    <path id="path2" transform="rotate(45 150 150)" d="M71.9 78.4C90.8 58.1 122.9 50.7 150.6 51.5c26.2 0.7 54.9 10.5 72.8 29.7 16.9 18.1 22.9 45.8 23.4 70.6 0.5 25.1-3.2 54.4-20.7 72.4-18.5 19.1-49.4 24.5-76 24.3-25.4-0.2-54.4-6.3-72.4-24.3C59.5 205.8 53.9 176.5 53 150.8 52.2 125.9 55 96.7 71.9 78.4Z" >
     <animateTransform attributeName="transform" type="rotate" values="360 148 148;0 148 148" begin="svg1.click" dur="20s" restart="whenNotActive" />  
    </path>
    <circle id="crc1" cx="150" cy="150" r="90" /> 
     <text id="txt1" x="80" y="160" font-size="36" font-weight="700" > Click me </text>
    </svg>  
    </div>

    • 3
  2. Qwertiy
    2022-04-09T02:00:57Z2022-04-09T02:00:57Z

    CSS.registerProperty && CSS.registerProperty({
      name: '--linepos',
      syntax: '<length-percentage>',
      inherits: true,
      initialValue: 0,
    });
    html, body, main {
      height: 100%;
      margin: 0;
    }
    
    main {
      --linepos: 50%;
      background: linear-gradient(to right, chocolate, white 50%, brown);
      background: linear-gradient(to right, chocolate, white var(--linepos), brown);
      animation: linepos 3s alternate infinite;
    }
    
    @keyframes linepos {
      from { --linepos: 0% }
      to { --linepos: 100% }
    }
    
    @property --linepos {
      syntax: '<length-percentage>';
      inherits: true;
      initial-value: 0;
    }
    <main></main>

    有这样的扭曲,但到目前为止还没有解决:

    CSS.registerProperty && CSS.registerProperty({
      name: '--linepos',
      syntax: '<length-percentage>',
      inherits: true,
      initialValue: 0,
    });
    
    CSS.registerProperty && CSS.registerProperty({
      name: '--slope',
      syntax: '<angle>',
      inherits: true,
      initialValue: "0turn",
    });
    html, body, main {
      height: 100%;
      margin: 0;
    }
    
    main {
      --linepos: 50%;
      --slope: .25turn;
      background: linear-gradient(to right, chocolate, white 50%, brown);
      background: linear-gradient(var(--slope), chocolate, white var(--linepos), brown);
      animation: anim 10s infinite;
    }
    
    @keyframes anim {
      from   { --linepos:   0%;   --slope:  .25turn; }
      50%    { --linepos: 100%;   --slope:  .75turn; }
      to     { --linepos:   0%;   --slope: 1.25turn; }
    }
    
    @property --linepos {
      syntax: '<length-percentage>';
      inherits: true;
      initial-value: 0;
    }
    
    @property --slope {
      syntax: '<angle>';
      inherits: true;
      initial-value: 0turn;
    }
    <main></main>

    • 3
  3. Sevastopol'
    2022-04-06T23:25:13Z2022-04-06T23:25:13Z

    我建议根据第一个(简化的)场景使用SMIL SVG.

    为了实现这样的动画,我们需要为渐变添加一种颜色——白色:

    <stop stop-color="white">
    

    添加动画,并为其指定必要的属性和值:

    attributeName=offset——该参数负责渐变区域的边界;

    dur=5s— 动画持续时间;

    values=0;1;0- 将确定动画顺序的值列表;

    repeatCount=indefinite- 动画执行的次数。该值indefinite表示动画将无限重复。

    所有这些都包含在一个标签中<animate>:

    <animate attributeName="offset" dur="5s" values="0;1;0" repeatCount="indefinite" />
    

    html, body, svg {margin: 0; padding: 0; width: 100%; height: 100vh;}
    <svg id="svg">
    <defs>
    <linearGradient id="gradient">
    <stop offset="0" stop-color="brown"/>
    <stop stop-color="white">
    <animate attributeName="offset" dur="5s" values="0;1;0" repeatCount="indefinite" /></stop>
    <stop offset="1" stop-color="chocolate"/>
    </linearGradient>
    </defs>
    <rect x="0" y="0" width="100%" height="100vh" fill="url(#gradient)"/>

    让我们将渐变线的斜率旋转 90 o

    html, body, svg {margin: 0; padding: 0; width: 100%; height: 100vh;}
    <svg id="svg">
    <defs>
    <linearGradient id="gradient" gradientTransform="rotate(90 0 0)">
    <stop offset="0" stop-color="brown"/>
    <stop stop-color="white">
    <animate attributeName="offset" dur="5s" values="0;1;0" repeatCount="indefinite" /></stop>
    <stop offset="1" stop-color="chocolate"/>
    </linearGradient>
    </defs>
    <rect x="0" y="0" width="100%" height="100vh" fill="url(#gradient)"/>

    • 2
  4. Alexandr_TT
    2022-04-07T16:19:11Z2022-04-07T16:19:11Z

    解决方案

    白条及其动画出现在悬停时

    • 白色条纹由linear-gradient
     background:linear-gradient(to bottom,brown, #fff 30px, chocolate 60px)
       no-repeat 0 -100px /100% 10%, chocolate;
    
    • 白条运动的动画是通过改变实现的 background-position

    水平动画

    body{
      margin:0;
      padding:0;
    }
    .box{
      width:100vw;
      height:50vh;
      background-color:chocolate;
      min-height:25vh;
     
    }
    .box:hover{
      background:linear-gradient(to right,brown, #fff 30px, chocolate 60px) no-repeat -100px 0/100px 100%, chocolate;
     animation:draw 3s ease-in-out alternate infinite; 
    }
    @keyframes draw{
      from{
        background-position:-35px 0;
      }
      to{
        background-position:105% 0;
      }
    }
    <div class="box"></div>

    垂直动画

    body{
      margin:0;
      padding:0;
    }
    .box{
      width:15vw;
      height:100vh;
      background-color:chocolate;
      min-height:50vh;
      transition:all .4s ease-in-out;
    }
    .box:hover{
      background:linear-gradient(to bottom,brown, #fff 30px, chocolate 60px) no-repeat 0 -100px /100% 10%, chocolate;
      animation:draw 4s ease-in-out alternate infinite;
    }
    @keyframes draw{
      from{
        background-position:5% 0%;
      }
      to{
        background-position: 5% 105%;
      }
    }
    <div class="box"></div>

    • 2
  5. Sevastopol'
    2022-04-09T02:02:08Z2022-04-09T02:02:08Z

    我建议根据使用技术的第一个(简化)场景来考虑动画选项CSS

    在这个版本中,我们可以使用伪元素::before和::after元素来实现这样的动画<body>,以及@keyframes通过设置常用关键帧的规则,包括其中的宽度属性width(用于第一个选项)或高度height(用于第二个选项)。

    html, body {margin: 0; padding: 0; width: 100%; height: 100vh; position: relative;}
    
    body::before, body::after {
      content: ""; display: block; height: 100vh; width: 100%;
      position: absolute; top: 0; bottom: 0;
    }
    
    body::before {
      left: 0; background: linear-gradient(90deg, brown, white);
      animation: before 5s linear infinite;
    }
    
    body::after {
      right: 0; background: linear-gradient(90deg, white, chocolate);
      animation: after 5s linear infinite;
    }
    
    @keyframes before {
      0% {width: 0;}
      50% {width: 100%;}
      100% {width: 0;}
    }
    
    @keyframes after {
      0% {width: 100%;}
      50% {width: 0;}
      100% {width: 100%;}
    }

    让我们将渐变线的斜率旋转 90 o

    html, body {margin: 0; padding: 0; width: 100%; height: 100vh; position: relative;}
    
    body::before, body::after {
      content: ""; display: block; height: 100vh; width: 100%;
      position: absolute; left: 0; right: 0;
    }
    
    body::before {
      top: 0; background: linear-gradient(180deg, brown, white);
      animation: before 5s linear infinite;
    }
    
    body::after {
      bottom: 0; background: linear-gradient(180deg, white, chocolate);
      animation: after 5s linear infinite;
    }
    
    @keyframes before {
      0% {height: 0;}
      50% {height: 100%;}
      100% {height: 0;}
    }
    
    @keyframes after {
      0% {height: 100%;}
      50% {height: 0;}
      100% {height: 100%;}
    }

    • 2

相关问题

  • 第二个 Instagram 按钮的 CSS 属性

  • 由于模糊,内容不可见

  • 弹出队列。消息显示不正确

  • 是否可以在 for 循环中插入提示?

  • 如何将 JSON 请求中的信息输出到数据表 Vuetify vue.js?

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    表格填充不起作用

    • 2 个回答
  • Marko Smith

    提示 50/50,有两个,其中一个是正确的

    • 1 个回答
  • Marko Smith

    在 PyQt5 中停止进程

    • 1 个回答
  • Marko Smith

    我的脚本不工作

    • 1 个回答
  • Marko Smith

    在文本文件中写入和读取列表

    • 2 个回答
  • Marko Smith

    如何像屏幕截图中那样并排排列这些块?

    • 1 个回答
  • Marko Smith

    确定文本文件中每一行的字符数

    • 2 个回答
  • Marko Smith

    将接口对象传递给 JAVA 构造函数

    • 1 个回答
  • Marko Smith

    正确更新数据库中的数据

    • 1 个回答
  • Marko Smith

    Python解析不是css

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5