Dlaczego to nie działa i jakie jest rozwiązanie?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body style="margin: 0">
<form name="a">
<input id="width" type="hidden"/>
<input id="height" type="hidden" />
</form>
<div id="a" style="position: relative;top: 0;left: 0;background-color: blue">
</div>
<script>
function a() {
var a = window.innerWidth;
var b = window.innerHeight;
var c = b - a;
var d = a - b;
//Don't forget to define units to pixels!
document.forms['a'].width.value = a;
document.forms['a'].height.value = b;
if(a < b){
document.getElementById("a").style.height = a + "px";
document.getElementById("a").style.width = a + "px";
document.getElementById("a").style.top = c / 2 + "px";
}else {
document.getElementById("a").style.height = b + "px";
document.getElementById("a").style.width = b + "px";
document.getElementById("a").style.left = d / 2 + "px";
}
}
var myInterval = setInterval(function() { if(document.forms['a'].width.value == window.innerWidth || document.forms['a'].height.value == window.innerHeight) {a();}}, 2500);
}
</script>
</body>
</html>
Bardzo prosze o odpowiedz :)