您的位置:首页 > 其它

如何设置SVG对象的高度和宽度?

2006-08-18 21:36 429 查看
<?xml version="1.0" encoding="UTF-8"?>
<?AdobeSVGViewer resolution="1200" save="snapshot"?>
<svg id="tstSVG" viewBox= "0 0 1000 1000" preserveAspectRatio= "xMidYMid meet" xmlns:xlink="http://www.w3.org/1999/xlink";>
<script>
try
{
var oParentWin= (window.parent)?(window.parent):(window.__parent__);
var oParentBody= oParentWin.document.body;
var oSVG= null;
var fZoom= 1.0;
function onResize(event)
{
try
{
if (!oSVG)
{
window.focus();//
make sure oSVG= oParentWin.document.activeElement;
oParentBody.style.overflow= "auto";
setTimeout("oSVG=oParentWin.document.activeElement;onResize(null);", 250);
}
else
{
//((oSVG.tagName=="EMBED"))
try
{
if (!event)
return false;
switch((event.type)?(event.type):(""))
{
case "mousewheel":
{
var actDefaultAntialias= window.getDefaultAntialias();
if(actDefaultAntialias)
setDefaultAntialias(false);
if(isNaN(fZoom))
fZoom= 1.0;
var fInc= (event.wheelDelta >= 120)?(.1):(-.1);
fZoom= (fZoom>1)?(Math.floor(fZoom+fInc*10)):(fZoom+fInc);
fZoom= Math.max(.1, Math.min(10., fZoom));
oSVG.style.zoom= fZoom;
oSVG.height= oParentBody.clientHeight;
oSVG.width= oParentBody.clientWidth;
if(actDefaultAntialias)
setTimeout("window.setDefaultAntialias("+actDefaultAntialias+")", 1000);
oParentWin.status= "Zoom: " + oSVG.style.zoom;
}
break;
default:
{
oSVG.style.posHeight = oParentBody.clientHeight;
oSVG.style.posWidth= oParentBody.clientWidth;
oParentWin.status= ("Resized: [" + oParentBody.clientHeight + "x" + oParentBody.clientWidth + "]");
}
}//switch(evt.type)
}
catch(e)
{
alert(e.description);
}
}
}
catch(e)
{
alert(e.description);
}
}
{
oParentWin.attachEvent("onresize",onResize);
oParentWin.attachEvent("onbeforeprint", onResize);
oParentWin.document.attachEvent("onmousewheel", onResize);
};
}
catch(e)
{
alert(e.description);
}
</script>
<style type="text/css">
<![CDATA[
@media print
{
}
]]>
</style>
<g style="fill:red; stroke:navy;">
<circle cx="500" cy="500" r="100" style="fill:gold;"/>
<path d="M0,495 l1000,0 l0,10 l-1000,0 z" />
<path d="M495,0 l10,0 l0,1000 l-10,0 z" />
</g>
</svg>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: