Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript window.onresize on page load

I have a script which shows different content depending on the screen size, it looks like this:

window.onresize = function(event) {
if ((window.innerWidth > 750 && window.innerWidth < 1250))  {

//Do something

}}

The above works absolutely fine when re-sizing the browser. My question is how can i get the above to work if the user opens the page up with a window width of say 750?

I have just tested this and obviously the event isn't triggered until the browser is re-sized, this is causing the above not to work

like image 726
danyo Avatar asked Feb 15 '23 17:02

danyo


1 Answers

var onResizing = function(event) {
if ((window.innerWidth > 750 && window.innerWidth < 1250))  {

//Do something

}};

window.onresize = onResizing;
window.onload = onResizing;
like image 130
Lwyrn Avatar answered Feb 18 '23 10:02

Lwyrn