在snap.svg中如何应用viewBox属性?

时间:2016-12-06 03:20:39

标签: svg viewbox

我在snap google,group上问了这个问题,但我也会在这里试试。我将viewBox属性应用于新的Snap对象时遇到了问题。

 s= Snap(400, 400);
 var bodyPath = s.path(bodyUp).attr({ "viewBox":"0 0 1378.4 1332", stroke: '#000', 'strokeWidth': 2, fill: 'transparent'});

这导致svg没有viewBox属性:

 <svg height="400" version="1.1" width="400" xmlns="http://www.w3.org/2000/svg"><desc>Created with Snap</desc><defs></defs><path d="M1036.2,822.6h327.2v-300h-177.2V304.4c0-4.3-0.2-8.6-0.6-12.8c0.4-4.2,0.6-8.5,0.6-12.8
    c0-82.8-67.2-150-150-150H712.9c0.2-2.5,0.3-5.1,0.3-7.6C713.2,62.5,665.7,15,607.1,15S501,62.5,501,121.1c0,2.7,0.1,5.5,0.3,8.2
    c-76.9,6.4-137.3,70.9-137.3,149.5c0,1,0,2,0,3h-1.2c-10.6,112.7-16.4,236-16.4,365.2c0,44.3,0.7,87.9,2,130.6
    c-131.7,155.3-216.1,307.7-231.9,413.7c-43.1-18.6-77.8-21.3-95.3-3.8l118.9,118.9c0.3-0.6,0.6-1.3,1-1.9c0.2,0.2,0.3,0.3,0.5,0.5
    l253.2-253.2l116.9-109.5c39.8,173,185.6,301.2,359.3,301.2c68.2,0,132-19.7,186.8-54.2c17.2,42.2,39.5,67.7,63.8,67.7v-118.3l0,0
    v-54.6c-187.5-19.4-334-188.7-334-394.6V428.8h98.5v243.9C886.2,755.5,953.4,822.6,1036.2,822.6z" viewBox="0 0 1378.4 1332" stroke="#000000" style="stroke-width: 2;" fill="rgba(0,0,0,0)" width="400" height="400" datashit="3"></path><path stroke="#000000" fill="rgba(0,0,0,0)" transform="matrix(1,0,0,1,5,5)" style="stroke-width: 2;"></path></svg>

viewBox。 我正在使用的图片相当大,我似乎无法在没有viewBox的情况下包含它。

1 个答案:

答案 0 :(得分:0)

您错误地将viewBox添加到<path>元素。它需要添加到<svg>元素。