I am trying to make a full RWD webpage using HTML5, CSS3, and JavaScript.
I have used @media in my CSS stylesheet file to set aside
width:0; and hidden overflow, in small devices. I added a button that calls java scripts to minimize article
and maximize aside
menu, and another button to minimize aside
and return article
.
The following code is called:
function openaside() {
document.getElementById("article").style.width = "0";
document.getElementById("aside").style.width = "100%";
document.getElementById("showasidebtn").style.width = "0";
document.getElementById("hideasidebtn").style.width = "25pX";
}
function closeaside() {
document.getElementById("article").style.width = "100%";
document.getElementById("aside").style.width = "0";
document.getElementById("showasidebtn").style.width = "25px";
document.getElementById("hideasidebtn").style.width = "0";
}
My page correctly responds to screen size and my scripts work fine. However when I use these scripts to change style and then change screen size, my article
and aside
width do not dynamically change until I refresh the page.
I have added the following JavaScript code to refresh page when screen is resized:
window.addEventListener("resize", onresize);
function onresize(){
location.reload(false)
}
Thanks every one I Find a way, instead of
function onresize(){
location.reload(false)
}
I use:
function onresize(){
document.getElementById("article").style.width = "";
document.getElementById("aside").style.width = "";
document.getElementById("showasidebtn").style.width = "";
document.getElementById("hideasidebtn").style.width = "";
}
But article minimize when the screen is moved in phones (e.g. scrolling). So now phone users should first scroll then open side menu. Could you help me find a better way? Is there any way to call a script when screen width exceed a certain amount?