[英]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);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.