使用javascript窗口函数的动态SVG背景

使用javascript窗口函数的动态SVG背景,javascript,dynamic,svg,window,Javascript,Dynamic,Svg,Window,我试图将我的背景设置为SVG图像。但是,我希望使用javascript窗口函数动态构造大小。这是逻辑 <script> function getWidth() { var w=window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; return w; } function getHeight() {

我试图将我的背景设置为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> 

函数getWidth()
{
var w=窗口宽度
||document.documentElement.clientWidth
||document.body.clientWidth;
返回w;
}
函数getHeight()
{
var h=窗内高度
||document.documentElement.clientHeight
||document.body.clientHeight;
返回h;
}
**var-wid=getWidth();
CSS3是解决方案

html, body
{
    height: 100%;
}

body {
    background:url(../Images/books.svg);
    background-size:100% 100%;
    background-repeat:no-repeat;
}

调整窗口大小时,需要更改此配置