The window.resize event fires only once

I am trying to accomplish things on window.resize, but I cannot even alert to work more than once. All the code I have is:

HTML:

<head>
    <meta charset="utf-8">
    <script src="jquery-1.11.1.min.js"></script>//I have this library in this html file directory
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>

  <script type="text/javascript">
    $(document).ready(function(){
      window.resize(alert("yolo"));
    });
  </script>
</head>
<body>
...
</body>

I also tried several options:

window.resize(...)

window.on("resize",...)

window.one("resize",...)

$(window).resize(...)

$(window).on("resize",...)

$(window).one("resize",...)

none of them work. Is there anything else I have not tried ???

+4
source share
2 answers

This is only called once since document.ready is consumed when the page loads.

$(document).ready(function(){
     window.resize(alert("yolo"));
});

You will need to bind the event handler to the window window.onresize = function() { alert("yolo"); }; or

$(window).resize(function () {alert("yolo");});

+3
source

alert('yolo') javascript. , .

window.resize , window.onresize :

window.onresize = function (){
    alert('yolo');
};
0

All Articles