[英]how do i loop an image to the full width/height of the page
I am trying to loop a small image to 100% width of the page using a for loop.我正在尝试使用 for 循环将小图像循环到页面的 100% 宽度。
var gameW = window.innerWidth;
var gameH = window.innerHeight;
var grass = document.getElementById("grass");
var sand = document.getElementById("sand");
grass.src = "images/grass.png"
function makeMap(){
for(var i = 0; i < gameW; i++){
grass++;
}
}makeMap();
You can do this with css (if that is an option).你可以用 css 来做到这一点(如果这是一个选项)。 background-repeat will probably do the job. background-repeat可能会完成这项工作。
For example, you can add a single div that has the width of your viewport and set its background to the image you want.例如,您可以添加一个具有视口宽度的 div,并将其背景设置为您想要的图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.