I'm quite new to JS and I am running into the same problem over and over again.
I simply do not know how to pass variables into functions the right way. There is something I am missing on, and I do not know what it is. And it is starting to get frustrating.
To change the height of a block on window resize; This works fine:
function changeGridFullScreen(event) {
var bodyHeaderHeight = document.getElementById('body-header').clientHeight;
var newHeight = window.innerHeight - bodyHeaderHeight;
var fsClasses = document.getElementsByClassName("grid-full-screen");
for(var i=0; i<fsClasses.length; i++){
fsClasses[i].style.height = newHeight+"px";
document.getElementById("logger").innerHTML = newHeight+"px";
}
}
window.addEventListener('resize', changeGridFullScreen, true);
But when I want to pass an array of some sorts. In this example the minimum clientHeight of a block. I simply do not know how to pass it, in all cases i break functionality. If tried several combinations, and probably am Googling on wrong search terms because i cant find a solution to this...
function changeGridFullScreen(event, minHeights) { // **<- what do i put in here**
var bodyHeaderHeight = document.getElementById('body-header').clientHeight;
var newHeight = window.innerHeight - bodyHeaderHeight;
var fsClasses = document.getElementsByClassName("grid-full-screen");
for(var i=0; i<fsClasses.length; i++){
if(newHeight >= minHeights[i]){
fsClasses[i].style.height = newHeight+"px";
}
}
}
function minHeights(){
var fsClasses = document.getElementsByClassName("grid-full-screen");
var minHeights = [];
for(var i=0; i<fsClasses.length; i++){
minHeights[i] = fsClasses[i].clientHeight;
}
return minHeights;
}
var heights = minHeights();
window.addEventListener('resize', changeGridFullScreen(heights), true); // **<- what do i put in here**
Anybody here to hand me the solution?