使用画布自动调整背景图像大小
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用画布自动调整背景图像大小相关的知识,希望对你有一定的参考价值。
The canvas drawImage size default is 300 x 150, so it's using the CSS to resize the canvas. Example posted at http://pastebin.me/76aed7005b1b413ea3c479287f4dbd59
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Conforming XHTML 1.0 Strict Template</title> </head> <body> <h2>Auto-resizing the background image using Canvas</h2> <canvas id="myCanvas" style="width: 100%; height: 100%; position: absolute; left: 0px; top: 0px; z-index: -1;"></canvas> var context = document.getElementById('myCanvas').getContext('2d'); var w = document.body.clientWidth; var h = document.body.clientHeight; img = new Image(); img.src='http://i201.photobucket.com/albums/aa236/Mottie1/testsite/screenshots/bg1.jpg'; img.onload = function () { context.drawImage(this,0,0,300,150); }; </script> </body> </html>
以上是关于使用画布自动调整背景图像大小的主要内容,如果未能解决你的问题,请参考以下文章