我创建了一个使用 raphaeljs 库绘制各种 SVG 元素的页面,但我在 Safari 中遇到了一些问题。
我正在绘制图像并使用剪切路径来掩盖某些区域。然后,用户可以单击“通过”这些图像到放置在后面的其他图像。
这在 Firefox 和 chrome 甚至 IE 中都可以正常工作。但在 Safari 中,我无法单击图像。剪切路径似乎在 Safari 中不起作用。
我通过这个问题发现,Safari 的内容类型必须设置为“application/xhtml+xml”,因为它没有使用 html5 解析器。
我已经尝试过将其放在页面顶部的建议...
<?php
header('Content-type: application/xhtml+xml');
?>
...但浏览器只输出 html 文件。
我只是想知道我需要什么 doctype 才能使 safari draw 正确嵌入 SVG,比如 chrome 和 firefox?
这就是我绘制 SVG 图像的方式,它在 chrome 和 firefox 中运行良好
function myDraw(path, url, x, y, w, h, id){
//create clipPath Element
var clippath = document.createElementNS("http://www.w3.org/2000/svg","clipPath");
clippath.setAttribute("id", id);
svgcanv.appendChild(clippath);
//draw the path
var cp=paper.path(path).translate(x, y).attr({stroke: 0});
$(cp.node).appendTo('#'+id+'');
//assoc clipPath with image
var img = paper.image(url,x,y,w,h);//.attr({fill:"#111",opacity:0.7});
img.node.setAttribute("clip-path","url(#"+id+")");
img.node.setAttribute("class",id);
}