How can I set window.innerHeight to fullsize?

// collect all the divs
var divs = document.getElementsByClassName('star');
// get window width and height
var winWidth = window.innerWidth;
var winHeight = window.innerHeight;

// i stands for "index". you could also call this banana or haircut. it's a variable
for ( var i=0; i < divs.length; i++ ) {
    
    // shortcut! the current div in the list
    var thisDiv = divs[i];
    
    // get random numbers for each element
    randomTop = getRandomNumber(0, winHeight);
    randomLeft = getRandomNumber(0, winWidth);
    
    // update top and left position
    thisDiv.style.top = randomTop +"px";
    thisDiv.style.left = randomLeft +"px";
    
}

// function that returns a random number between a min and max
function getRandomNumber(min, max) {
    
  return Math.random() * (max - min) + min;
    
}

How can I set that window.innerHeight to full screen size? Or setting to specific number like 2500px.

Now it just be small part in page.

How can I change it?

1 answer

  • answered 2021-01-11 05:32 Vahid

    You can get full screen with and height by this:

    let screenWidth = screen.availWidth;
    let screenheight = screen.availHeight;
    

    And set your div width and height like this:

    thisDiv.style.width = "200px";
    

    Edit:

    Sorry, maybe I didn't catch what do you want to do. Do you want to show divs randomly across the browser window? Then using window.innerWidth as you did, would be fine in first place, and you shouldn't change anything, but obviously something doesn't work fine. But refer to question, do you want to resize the browser window? For this there is a method that could resize the window, but it works only if windows was opened by ``window.open(...```. As I know, you can't resize the main browser or one Tab from javascript.