RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1356348
Accepted
Air
Air
Asked:2022-05-02 15:33:34 +0000 UTC2022-05-02 15:33:34 +0000 UTC 2022-05-02 15:33:34 +0000 UTC

你能帮我把这个css预加载器重写为svg吗?

  • 772

主要的是这个预加载器对于任何扩展都应该是一样的,而且符号也应该有一个渐变。当然,这可以在 上实现css,但这仍然是一种变态......

预先感谢您的帮助...

document.querySelector(".circle").innerHTML = "Loading..."
  .split("")
  .map((e, i) => `<span style="--rot:${i * 11}deg">${e}</span>`)
  .join("");
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
}

html,
body {
  height: auto;
  min-height: 100vh;
  background-color: #272727;
  color: burlywood;
  font-size: 2vw;
  border: 1px solid transparent;
}

body * {
  /* border: 1px solid red; */
}

.circle {
  margin: 100px auto;
  width: 20vw;
  height: 20vw;
  position: relative;
  border-radius: 50%;
  overflow: hidden;
}

.circle::after,
.circle::before {
  position: absolute;
  content: "";
  display: block;
  width: inherit;
  height: inherit;
  border-radius: 50%;
  /*
        */
}

.circle::after {
  animation: rott 1s ease infinite;
  background: linear-gradient(130deg, red 20%, purple 70%);
  background-position: -42px -29px;
  background-repeat: no-repeat;
  border: 30px solid #272727;
  box-sizing: border-box;
  border-top: 30px solid transparent;
  border-left: 30px solid transparent;
  background-size: 132% 120%;
}

.circle::before {
  background-color: #272727;
  transform: translate(-50%, -50%);
  z-index: 4;
  left: 50%;
  top: 50%;
  width: calc(20vw - 30px);
  height: calc(20vw - 30px);
}

span {
  z-index: 9;
  display: inline-flex;
  justify-content: center;
  align-items: flex-start;
  width: 30px;
  height: 100%;
  position: absolute;
  padding: 60px 0 0 0;
  top: 50%;
  left: 50%;
  transform-origin: 6px 56% 0;
  transform: translate(-50%, -50%) rotate(var(--rot));
}

span:nth-child(8) {
  animation: opa 1s ease 0s infinite;
}

span:nth-child(9) {
  animation: opa 1s ease 0.2s infinite;
}

span:nth-child(10) {
  animation: opa 1s ease 0.5s infinite;
}

@keyframes rott {
  0% {
    transform: rotate(0);
  }
  100% {
    transform: rotate(360deg);
  }
}

@keyframes opa {
  0% {
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
<div class="circle"></div>

css
  • 2 2 个回答
  • 10 Views

2 个回答

  • Voted
  1. Best Answer
    Alexandr_TT
    2022-05-02T21:00:48Z2022-05-02T21:00:48Z
    • 使用圆弧切割圆弧stroke-dasharray

    • 弧线用线性渐变着色

    • 通过更改属性旋转圆弧stroke-dashoffset

    • 实现旋转不均匀keyTimes="0;0.75;0.9;1"

    • Loading ...通过应用沿弧定位文本
      <textPath href="#textPath" startOffset="12">

    body {
    background:#272727;
    }
    .container {
    width:40vw;
    height:40vh;
    }
    <div class="container">
    <svg  xmlns="http://www.w3.org/2000/svg"  xmlns:xlink="http://www.w3.org/1999/xlink"
             viewBox="0 0 400 400"  > 
     <defs>    
                    <!-- Линейный градиент для окраски дуги с прозрачным хвостом -->
       <linearGradient id="Lg" x1="0" x2="0" y1="1" y2="0">
          <stop offset="0" stop-color="white" stop-opacity="0.05"  />
          <stop offset="0.8" stop-color="red"  />
       </linearGradient>
     </defs>    
                      <!-- Дуга, на которой расположены буквы  -->
    <path id="textPath" d="M200,110 A90,90 0 0 1 200,290" stroke-width="2" fill="none" stroke="none" /> 
    <text class="txt1" font-size="32px" letter-spacing="0.2em" fill="#DEB887">
      <textPath href="#textPath" startOffset="12">
        <tspan dy="-0.1em">Loading . . .</tspan>
      </textPath>
    </text>
                             <!-- Вращающаяся дуга -->
    <circle id="circle" cx="200" cy="200" r="150" stroke="url(#Lg)" stroke-width="20" stroke-dashoffset="942"  stroke-dasharray="471" fill="none" stroke="crimson" stroke-linecap="round" >
        <animate
         attributeName="stroke-dashoffset"
         begin="0s" dur="1s"
         values="942;471;235;0"
         keyTimes="0;0.75;0.9;1"
          calcMode="linear"
         repeatCount="indefinite" /> 
      
    </circle> 
    </svg>
    </div>

    更新

    添加了文字动画加载中...

    使用旋转并因此打开的遮罩半圆实现,遮盖文本

    <mask id="mask">    
          <rect width="100%" height="100%" fill="white" />
           <path transform="rotate(0,200,200)" d="M200,90 A110,110 0 0 1 200,310" stroke-width="20" fill="black" stroke="black" >  
          <animateTransform
         attributeName="transform"
         type="rotate"
         begin="0s" dur="4s"
         values="0,200,200;360,200,200"
         repeatCount="indefinite" /> 
         </path>    
    </mask>
    

    body {
    background:#272727;
    }
    .container {
    width:40vw;
    height:40vh;
    }
    <div class="container">
    <svg  xmlns="http://www.w3.org/2000/svg"  xmlns:xlink="http://www.w3.org/1999/xlink"
              viewBox="0 0 400 400"  > 
     <defs>
       <linearGradient id="Lg" x1="0" x2="0" y1="1" y2="0">
          <stop offset="0" stop-color="white" stop-opacity="0.05"  />
          <stop offset="0.8" stop-color="red"  />
            
       </linearGradient> 
       <mask id="mask">    
          <rect width="100%" height="100%" fill="white" />
           <path transform="rotate(0,200,200)" d="M200,90 A110,110 0 0 1 200,310" stroke-width="20" fill="black" stroke="black" >  
          <animateTransform
         attributeName="transform"
         type="rotate"
         begin="0s" dur="4s"
         values="0,200,200;360,200,200"
         repeatCount="indefinite" /> 
         </path>    
       </mask>
     </defs>         
    <path   id="textPath" d="M200,110 A90,90 0 0 1 200,290" stroke-width="2" fill="none" stroke="none" /> 
    <text  mask="url(#mask)" class="txt1" font-size="32px" letter-spacing="0.2em" fill="#DEB887">
      <textPath href="#textPath" startOffset="12">
        <tspan dy="-0.1em">Loading . . .</tspan>
      </textPath>
    </text>
      
    <circle id="circle" cx="200" cy="200" r="150" stroke="url(#Lg)" stroke-width="20" stroke-dashoffset="942"  stroke-dasharray="471" fill="none" stroke="crimson" stroke-linecap="round" >
        <animate
         attributeName="stroke-dashoffset"
         begin="0s" dur="1s"
         values="942;471;235;0"
         keyTimes="0;0.75;0.9;1"
          calcMode="linear"
         repeatCount="indefinite" /> 
      
    </circle> 
    </svg>
    </div>

    • 3
  2. Alexandr_TT
    2022-05-03T04:05:56Z2022-05-03T04:05:56Z

    带有渐变动画的变体

    在渐变中,offset构成渐变的两种颜色的属性都是动画的:

                      <!-- Линейный градиент для окраски текста -->
    <linearGradient id="LgText" x1="0" y1="0" x2="0.25" y2="1">
      <stop offset="5%" stop-color="orangered"  >
          <animate attributeName="offset" dur="3s" values="0;1;1" fill="freeze" repeatCount="indefinite" /> 
      </stop>
       <stop offset="95%" stop-color="#DEB887" >
          <animate attributeName="offset" dur="3s" values="0;1;1" fill="freeze" repeatCount="indefinite" /> 
       </stop>
    </linearGradient> 
    

    如果设置为values="0;1;1"重复1,它会在填充结束时暂停

    body {
    background:#272727;
    }
    .container {
    width:40vw;
    height:40vh;
    }
    <div class="container">
    <svg  xmlns="http://www.w3.org/2000/svg"  xmlns:xlink="http://www.w3.org/1999/xlink"
              viewBox="0 0 400 400"  > 
     <defs>    
                    <!-- Линейный градиент для окраски дуги с прозрачным хвостом -->
       <linearGradient id="Lg" x1="0" x2="0" y1="1" y2="0">
          <stop offset="0" stop-color="white" stop-opacity="0.05"  />
          <stop offset="0.8" stop-color="red"  />
       </linearGradient> 
                       <!-- Линейный градиент для окраски текста -->
    <linearGradient id="LgText" x1="0" y1="0" x2="0.25" y2="1">
      <stop offset="5%" stop-color="orangered"  >
          <animate attributeName="offset" dur="3s" values="0;1;1" fill="freeze" repeatCount="indefinite" /> 
      </stop>
       <stop offset="95%" stop-color="#DEB887" >
          <animate attributeName="offset" dur="3s" values="0;1;1" fill="freeze" repeatCount="indefinite" /> 
       </stop>
    </linearGradient> 
     </defs>    
                      <!-- Дуга, на которой расположены буквы  -->
    <path id="textPath" d="M200,110 A90,90 0 0 1 200,290" stroke-width="2" fill="none" stroke="none" /> 
    <text class="txt1" font-size="36px" font-weight="bold" letter-spacing="0.2em" fill="url(#LgText)">
      <textPath href="#textPath" startOffset="2">
        <tspan dy="-0.1em">Loading . . .</tspan>
      </textPath>
    </text>
                             <!-- Вращающаяся дуга -->
    <circle id="circle" cx="200" cy="200" r="150" stroke="url(#Lg)" stroke-width="20" stroke-dashoffset="942"  stroke-dasharray="471" fill="none" stroke="crimson" stroke-linecap="round" >
        <animate
         attributeName="stroke-dashoffset"
         begin="0s" dur="1s"
         values="942;471;235;0"
         keyTimes="0;0.75;0.9;1"
          calcMode="linear"
         repeatCount="indefinite" /> 
      
    </circle> 
    </svg>
    </div>       

    当values="0;1;1;0;0"将在两个方向进行绘画并在最终位置暂停时

    body {
    background:#272727;
    }
    .container {
    width:40vw;
    height:40vh;
    }
    <div class="container">
    <svg  xmlns="http://www.w3.org/2000/svg"  xmlns:xlink="http://www.w3.org/1999/xlink"
              viewBox="0 0 400 400"  > 
     <defs>    
                    <!-- Линейный градиент для окраски дуги с прозрачным хвостом -->
       <linearGradient id="Lg" x1="0" x2="0" y1="1" y2="0">
          <stop offset="0" stop-color="white" stop-opacity="0.05"  />
          <stop offset="0.8" stop-color="red"  />
       </linearGradient> 
                       <!-- Линейный градиент для окраски текста -->
       <linearGradient id="LgText" x1="0" y1="0" x2="0.25" y2="1">
      <stop offset="5%" stop-color="orangered"  >
          <animate attributeName="offset" dur="6s" values="0;1;1;0;0" fill="freeze" repeatCount="indefinite" /> 
        </stop>
       <stop offset="95%" stop-color="#DEB887" >
          <animate attributeName="offset" dur="6s" values="0;1;1;0;0" fill="freeze" repeatCount="indefinite" /> 
       </stop>
       
     </linearGradient> 
     </defs>    
                      <!-- Дуга, на которой расположены буквы  -->
    <path id="textPath" d="M200,110 A90,90 0 0 1 200,290" stroke-width="2" fill="none" stroke="none" /> 
    <text class="txt1" font-size="36px" font-weight="bold" letter-spacing="0.2em" fill="url(#LgText)">
      <textPath href="#textPath" startOffset="2">
        <tspan dy="-0.1em">Loading . . .</tspan>
      </textPath>
    </text>
                             <!-- Вращающаяся дуга -->
    <circle id="circle" cx="200" cy="200" r="150" stroke="url(#Lg)" stroke-width="20" stroke-dashoffset="942"  stroke-dasharray="471" fill="none" stroke="crimson" stroke-linecap="round" >
        <animate
         attributeName="stroke-dashoffset"
         begin="0s" dur="1s"
         values="942;471;235;0"
         keyTimes="0;0.75;0.9;1"
          calcMode="linear"
         repeatCount="indefinite" /> 
      
    </circle> 
    </svg>
    </div>       

    更新

    引用@Air 的评论:

    比如让条带与铭文处于同一水平,并穿过它……实际上,带有渐变的条带到达铭文的边界并消失,就好像在最后进入和退出它一样。 .. 它会很酷

    这个想法是使字母透明,只是与字母轮廓的线条,将它们包含在蒙版中并将该蒙版应用于旋转弧

    • 一个方向的阴影渐变选项

    body {
    background:#272727;
    }
    .container {
    width:40vw;
    height:40vh;
    }
    <div class="container">
    <svg  xmlns="http://www.w3.org/2000/svg"  xmlns:xlink="http://www.w3.org/1999/xlink"
              viewBox="0 0 400 400"  > 
     <defs>    
                    <!-- Линейный градиент для окраски дуги с прозрачным хвостом -->
       <linearGradient id="Lg" x1="0" x2="0" y1="1" y2="0">
          <stop offset="0" stop-color="white" stop-opacity="0.05"  />
          <stop offset="0.8" stop-color="red"  />
       </linearGradient> 
                       <!-- Линейный градиент для окраски текста -->
       <linearGradient id="LgText" x1="0" y1="0" x2="0.25" y2="1">
      <stop offset="5%" stop-color="orangered"  >
          <animate attributeName="offset" dur="2s" values="0;1" fill="freeze" repeatCount="indefinite" /> 
        </stop>
       <stop offset="95%" stop-color="#DEB887" >
          <animate attributeName="offset" dur="2s" values="0;1" fill="freeze" repeatCount="indefinite" /> 
       </stop>
       
     </linearGradient> 
     </defs>    
    
                             <!-- Вращающаяся дуга -->
    <circle id="circle" cx="200" cy="200" r="150" stroke="url(#Lg)" stroke-width="42" stroke-dashoffset="942"  stroke-dasharray="471" fill="none" stroke="crimson" stroke-linecap="round" >
        <animate
         attributeName="stroke-dashoffset"
         begin="0s" dur="1s"
         values="942;471;235;0"
         keyTimes="0;0.75;0.9;1"
          calcMode="linear"
         repeatCount="indefinite" /> 
      
    </circle> 
                        <!-- Дуга, на которой расположены буквы  -->
    <path id="textPath" d="M200,110 A90,90 0 0 1 200,290" stroke-width="2" fill="none" stroke="none" /> 
    <text class="txt1" font-size="36px" font-weight="bold" letter-spacing="0.2em" fill="url(#LgText)" stroke="#DEB887" >
      <textPath href="#textPath" startOffset="2">
        <tspan dy="-1.3em">Loading . . .</tspan>
      </textPath>
    </text>
    </svg>
    </div>       

    • 两个方向都有阴影渐变的选项

    body {
    background:#272727;
    }
    .container {
    width:40vw;
    height:40vh;
    }
    <div class="container">
    <svg  xmlns="http://www.w3.org/2000/svg"  xmlns:xlink="http://www.w3.org/1999/xlink"
              viewBox="0 0 400 400"  > 
     <defs>    
                    <!-- Линейный градиент для окраски дуги с прозрачным хвостом -->
       <linearGradient id="Lg" x1="0" x2="0" y1="1" y2="0">
          <stop offset="0" stop-color="white" stop-opacity="0.05"  />
          <stop offset="0.8" stop-color="red"  />
       </linearGradient> 
                       <!-- Линейный градиент для окраски текста -->
       <linearGradient id="LgText" x1="0" y1="0" x2="0.25" y2="1">
      <stop offset="5%" stop-color="orangered"  >
          <animate attributeName="offset" dur="6s" values="0;1;1;0;0" fill="freeze" repeatCount="indefinite" /> 
        </stop>
       <stop offset="95%" stop-color="#DEB887" >
          <animate attributeName="offset" dur="6s" values="0;1;1;0;0" fill="freeze" repeatCount="indefinite" /> 
       </stop>
       
     </linearGradient> 
     <mask id="mask">
       <rect width="100%" height="100%" fill="white"/>
       <g fill="black"> 
           <path id="textPath" d="M200,110 A90,90 0 0 1 200,290"  fill="black" stroke="none" /> 
    <text class="txt1" font-size="36px" font-weight="bold" letter-spacing="0.2em"  stroke="black" >
      <textPath href="#textPath" startOffset="2">
        <tspan dy="-1.3em">Loading . . .</tspan>
      </textPath>
    </text>
       </g>
     </mask>
     </defs>      
     
                         <!-- Дуга, на которой расположены буквы  -->
    <path id="textPath" d="M200,110 A90,90 0 0 1 200,290" stroke-width="2" fill="none" stroke="none" /> 
    <text class="txt1" font-size="36px" font-weight="bold" letter-spacing="0.2em" fill="url(#LgText)" stroke="#DEB887" >
      <textPath href="#textPath" startOffset="2">
        <tspan dy="-1.3em">Loading . . .</tspan>
      </textPath>
    </text>
    
                             <!-- Вращающаяся дуга -->
    <circle id="circle" cx="200" cy="200" r="150" mask="url(#mask)" stroke="url(#Lg)" stroke-width="42" stroke-dashoffset="942"  stroke-dasharray="471" fill="none"  stroke-linecap="round" >
        <animate
         attributeName="stroke-dashoffset"
         begin="0s" dur="1s"
         values="942;471;235;0"
         keyTimes="0;0.75;0.9;1"
          calcMode="linear"
         repeatCount="indefinite" /> 
      
    </circle> 
    
    </svg>
    </div>       

    • 2

相关问题

  • 几何形状的阴影

  • 如何制作这样的人物组合?

  • 如何在css中制作一个图形

  • 如何制作阴影(投影)渐变

  • 网格项目传输不起作用

  • 更改屏幕宽度时换行。引导程序

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