我需要在一些其他元素上將生成的內聯SVG設置爲background-image
,如in this example所示。由於這隻適用於Chrome,我需要其他方式將客戶端繪製的SVG設置爲background-image
。如何在服務器上轉換內聯SVG?
另一種可能更簡單的內聯SVG是RaphaelJS演示,作爲seen here。
<svg height="480" version="1.1" width="640" xmlns="http://www.w3.org/2000/svg" style="overflow: hidden; position: relative; top: -0.90625px;"><desc style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);">Created with Raphaël 2.1.0</desc><defs style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></defs><rect x="0" y="0" width="640" height="480" r="10" rx="10" ry="10" fill="#ffffff" stroke="none" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></rect><circle cx="320" cy="240" r="60" fill="#223fa3" stroke="#000000" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); stroke-opacity: 0.5;" stroke-width="80" stroke-opacity="0.5"></circle></svg>
是否有可能在服務器上聯SVG(由RaphaelJS在客戶端上創建)轉換爲一個「真正」的SVG文件?這是一個Windows(.NET/c#)服務器環境,應在其上進行轉換。
編輯
正如羅伯特Longson發現我失蹤了charset=
,另外它看起來像我使用了錯誤的函數(encodeURI
)來編碼聯SVG。
只是爲了完整起見這裏設定的是對我的作品
var svgUrl = 'url("data:image/svg+xml;charset=utf8,' + encodeURIComponent($('#raphaelPaper').html()) + '")';
$('#pictureDummy').css('background-image', svgUrl);
你爲什麼不簡單的得到'''
@Blackhole它看起來像內聯的'
我剛剛找到一個名爲'Raphael.Export'的圖書館。看起來它可以將客戶端生成的SVG導出到.svg文件。但不知道它是否適用於我生成的東西。嘗試一下。 – pantarhei