2013-02-12 38 views
0

我想將我的背景設置爲SVG圖像。不過,我希望使用JavaScript窗口函數動態構建大小。這是邏輯...使用javascript窗口函數的動態SVG背景

<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> 
+0

您需要在調整窗口大小的同時更改此配置 – lindosekai 2013-02-12 09:39:02

回答

0

CSS3是解決方案。

html, body 
{ 
    height: 100%; 
} 

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