所以我想用图片填充SVG文本的背景。如果我将它设置在SVG代码中,它可以正常工作。但我想单击一个按钮,然后将它应用到文本的图像背景。 Here is a fiddle containing all of the code.jQuery不支持SVG
下面是代码反正
<body>
<button>Text</button>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<pattern id="patt1" patternUnits="userSpaceOnUse" width="10" height="10">
<image xlink:href="http://dunnrite.co.uk/Images/pattern1.jpg" width="10" height="10" />
</pattern>
</defs>
<text x="20" y="170">Your words here</text>
</svg>
$(document).ready(function(){
$("button").click (function() {
$("text").css("fill", "url(#patt1)");
});
});
感谢
在这里工作很好http://jsfiddle.net/xWNR3/102/ – 2014-09-12 10:46:27
@MohitArora无法使用最新的稳定铬...现在是 – Mardoxx 2014-09-12 10:46:57
@Mardoxx你检查了我的演示吗? – 2014-09-12 10:48:57