I am trying to loop a small image to 100% width of the page using a for loop.
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). background-repeat will probably do the job.
For example, you can add a single div that has the width of your viewport and set its background to the image you want.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.