javascript - 增加 svg 的加载器宽度

标签 javascript html css svg

我试图增加圆 svg 的旋转宽度但失败了,知道要调整哪个值吗?

<div class="loader">
  <svg version="1.1" id="loader-1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     width="30px" height="30px" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50;" xml:space="preserve">
  <path fill="#3b5998" d="M43.935,25.145c0-10.318-8.364-18.683-18.683-18.683c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615c8.072,0,14.615,6.543,14.615,14.615H43.935z">
    <animateTransform attributeType="xml"
      attributeName="transform"
      type="rotate"
      from="0 25 25"
      to="360 25 25"
      dur="0.6s"
      repeatCount="indefinite"/>
    </path>
  </svg>
</div>

最佳答案

您应该使用 strokestroke-width 属性来增加旋转区域的宽度,如下所示:

<svg ...>
     <path ... stroke="#3b5998" stroke-width="5"></path>
</svg>

路径必须有 stoke 属性,让路径使用 stroke-width 增加宽度。

<div class="loader">
  <svg version="1.1" id="loader-1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     width="30px" height="30px" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50;" xml:space="preserve" >
  <path stroke="#3b5998" d="m43.935,25.145c0-10.318-8.364-18.683-18.683-18.683c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615c8.072,0,14.615,6.543,14.615,14.615H43.935z" stroke-width="5">
    <animateTransform attributeType="xml"
      attributeName="transform"
      type="rotate"
      from="0 25 25"
      to="360 25 25"
      dur="0.6s"
      repeatCount="indefinite"/>
    </path>
  </svg>
    
  
</div>

编辑:您还可以像这样使用自定义图像背景作为描边:

<svg ...>
 <defs>
    <pattern id="p1" patternUnits="userSpaceOnUse" width="32" height="32">
      <image xlink:href="http://i.stack.imgur.com/NIXg7.jpg" width="32" height="32" />
    </pattern>
 </defs>
 <path ... stroke="url(#p1)" stroke-width="5"></path>
</svg>

<div class="loader">
  
    <svg version="1.1" id="loader-2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     width="30px" height="30px" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50;" xml:space="preserve" >
    <defs>
    <pattern id="p1" patternUnits="userSpaceOnUse" width="32" height="32">
      <image xlink:href="http://i.stack.imgur.com/NIXg7.jpg" width="32" height="32" />
    </pattern>
  </defs>
  <path stroke="url(#p1)" d="m43.935,25.145c0-10.318-8.364-18.683-18.683-18.683c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615c8.072,0,14.615,6.543,14.615,14.615H43.935z" stroke-width="5">
    
    <animateTransform attributeType="xml"
      attributeName="transform"
      type="rotate"
      from="0 25 25"
      to="360 25 25"
      dur="0.6s"
      repeatCount="indefinite"/>
    </path>
    
  </svg>
</div>

关于javascript - 增加 svg 的加载器宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38035833/

相关文章:

javascript - 我可以使用一组限制来模拟 JavaScript 中的函数式编程吗?

javascript - 重定向后的 React-router-redux setState 警告

用于加载数据 JSON 文件的 JavaScript 代码

javascript - Google+ 样式自动完成 + 下拉 jQuery 插件

Javascript - 更改二维数组的名称

objective-c - iOS 中的 native 应用程序可以使用哪些 Web 应用程序不能使用的功能/技术?

html - 如何在输入值下方画线并装饰这条线

javascript - 如何在 &lt;textarea&gt; 中显示不可见字符

css - 使用 CSS 网格功能时图像宽度超过容器宽度

c# - 如何从模型中获取图像以在 CSS 样式标签的 View 中使用?