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

<?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> 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值