0

我正在尝试将我的背景设置为 SVG 图像。但是,我希望使用 javascript 窗口函数动态构造大小。这是逻辑...

<script>
  function getWidth()
  {
    var w=window.innerWidth
    || document.documentElement.clientWidth
    || document.body.clientWidth;

    return w;

  }

  function getHeight()
  {
    var h=window.innerHeight
    || document.documentElement.clientHeight
    || document.body.clientHeight;

    return h;

  }

</script>

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">

**var wid = getWidth();
  <rect width=wid height="100"**
  style="fill:rgb(0,0,255);stroke-width:1;stroke:rgb(0,0,0)"/>
</svg> 
4

1 回答 1

0

CSS3 是解决方案。

html, body
{
    height: 100%;
}

body {
    background:url(../Images/books.svg);
    background-size:100% 100%;
    background-repeat:no-repeat;
}
于 2013-09-24T23:35:15.493 回答