There is the most common script for resizing:

function heightDetect() { $(".carousel").css("height", $(window).height()); } heightDetect(); $(window).resize(function(){ heightDetect(); }); 

Script checked, not the first time I use. But now there was a problem that I encountered for the first time. I want to make a "carousel" in full screen, when the page first loads, nothing happens, the script only works if CHANGE AT ONE PIXEL screen resolution! After updating the page, everything comes back.

Has anyone encountered this problem? Please tell me how to solve it?

  • Maybe when executing the script object $ (". Carousel") is not? Where do you load the script? Try adding the string console.log ($ (". Carousel")) to the function to see if it finds such an element or not - Sergey
  • @ Sergey Strange, it starts to see him only after changing the screen size. I load the script immediately after $ (document) .ready (function () {. - Artem

2 answers 2

Here is the correct version. Works great:

 function heightDetect() { $(".carousel").css("height", $(window).height()) } $(window).on("load",function(){ heightDetect(); }); 

You just need to change the resire to onload.

  • Do not change. Now resize will not work. - Qwertiy

You can add a resize event for everyone else, in addition to load, if the window can change its size, then

  • Yes, as an option ...) - Artem