2015-07-19 54 views
1

我的canvas元素目前有以下属性:设置高度涵盖滚动页面的整体

var c = document.getElementById("c"); 
    var ctx = c.getContext("2d"); 

    //making the canvas full screen 
    c.height = window.innerHeight; 
    c.width = window.innerWidth; 

当我把画布具有比能够适应屏幕的高度,更多的内容在页面上,当我向下滚动时,画布会切断,这是可以预料的。如何更改高度属性以使画布最大限度地延伸至页面上的内容?

回答

0

使用此:

var c = document.getElementById("c"); 
    var ctx = c.getContext("2d"); 

    //making the canvas full screen 
    c.height = document.getElementsByTagName('body')[0].scrollHeight; 
    c.width = window.innerWidth; 
+0

有'scrollWidth'的宽度为好。 –