簡體   English   中英

如何更改svg中文本元素的屬性?

[英]How to change an attribute of a text element inside a svg?

我有這個SVG來實現文本漸變。 如何使用jQuery更改font-size屬性?

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="600" height="40" class="detail_val_svg">
  <defs>
    <linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="100%">
      <stop offset="0%" style="stop-color:#4FB6D7;stop-opacity:1" />
      <stop offset="100%" style="stop-coloR:#325FF3;stop-opacity:1" />
    </linearGradient>
  </defs>
  <text fill="url(#grad1)" font-size="34" font-family="Helvetica" x="0" y="28">
    MY TEXT HERE
  </text>
</svg>

 $(document).ready(function() { $('svg text').css('font-size', 8); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="600" height="40" class="detail_val_svg"> <defs> <linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="100%"> <stop offset="0%" style="stop-color:#4FB6D7;stop-opacity:1" /> <stop offset="100%" style="stop-coloR:#325FF3;stop-opacity:1" /> </linearGradient> </defs> <text fill="url(#grad1)" font-size="34" font-family="Helvetica" x="0" y="28"> MY TEXT HERE </text> </svg> 

您還可以將attr屬性用作設置器。

$(document).ready(function() {
    $('svg text').attr('font-size', 12);
});

http://jsfiddle.net/vraxwppz/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM