Currently, I am working on a layout that includes a toolbar and a main div. In my design, the positioning of the toolbar should change based on the window's dimensions. If the Y axis is smaller than the X axis, the toolbar needs to be on the left side. Conversely, if the X axis is smaller than the Y axis, the toolbar should be placed at the top. However, despite my efforts to position the toolbar absolutely at the top: 0 and left: 0, and adjusting the width and height properties upon resizing, my code does not seem to be functioning correctly.
Javascript:
window.onresize = function(event) {
winW = window.innerWidth;
winH = window.innerHeight;
console.debug("x axis:" + winW + "y axis:" + winH);
if(winW < winH){
var elem = document.getElementById('div1');
console.debug("test" + elem.style.width);
var a = elem.style.height;
elem.style.height = elem.style.width;
elem.style.width = a;
}
else{
var elem = document.getElementById('div1');
elem.style.height = elem.style.height;
elem.style.width = elem.style.width;
}
}
CSS:
#div1{
background: red;
position:absolute;
height:100%;
width:20px;
top:0;
left:0;
}
#div2{
width:100%;
height:500px;
background-color:green;
margin-left: 20px;
}