增加svg的装载机宽度

时间:2016-06-26 06:33:52

标签: 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>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

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

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

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

&#13;
&#13;
<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>
&#13;
&#13;
&#13;

编辑:你也可以使用自定义图像背景作为笔画:

<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>

&#13;
&#13;
<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>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

我从width="30px" height="30px"更改为width="300px" height="300px"。我不是100%确定这是你的意思:

&#13;
&#13;
<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="300px" height="300px" 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>
&#13;
&#13;
&#13;