刚毅87
2016-07-16 16:39
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> *{ margin: 0; padding: 0; } </style> </head> <body> <canvas id="myCanvas" height="" width=""> 此浏览器不支持canvas,请更换浏览器 </canvas> <script type="text/javascript"> var canvas = document.getElementById('myCanvas'); var context = canvas.getContext('2d'); canvas.width = document.documentElement.clientWidth; canvas.height = document.documentElement.clientHeight; var imgs = new Image(); imgs.src = 'img/background.png'; var bgY = 0; function bgmove(){ context.clearRect(0,0,canvas.width,canvas.height); bgY++; var pattarn = context.createPattern(imgs,'repeat'); console.log(bgY); context.fillRect(0,bgY,canvas.width,canvas.height/2); context.fillStyle = pattarn; context.fill(); } setInterval(bgmove,30) </script> </body> </html>
想让背景图随 cancas 的移动而移动,该如何改进,求大神指导.
canvas 肯定可以移动,我说的是怎么让填充的图片随 canvas 一起移动
canvas也能移动呀!你是说,层叠的canvas吗?
Canvas绘图详解
72885 学习 · 422 问题
相似问题