If any method so that as soon as the user reaches 1024px, the function starts its work? For example, $(window).on('resizeEnd', function(){} will work?

  • one
    What for? What does this feature do? Maybe this needs to be done in CSS? - Alexey Ten
  • @AlexeyTen No, he will calculate the distance from the parent to the block and give him the distance from the top. Can you do it on css?) - Nikita Shchypylov
  • @AlexeyTen, and the scripts that need to be called only at a certain size of the device's browser window, will you also via css ? - MasterAlex
  • @ Nikita Schipilov need to look at the specific layout. Maybe I Can - Alexey Ten
  • @MasterAlex so I asked what the script does. Too often, instead of a couple of lines on the css, terrible incomprehensible and stupid scripts begin to fence - Alexey Ten

1 answer 1

So earn:

 $(document).ready(function(){ var started = false; if (document.documentElement.clientWidth > 1023 && !start) { // Код, который нужно исполнить started = true; } $(window).resize(function() { if (document.documentElement.clientWidth > 1023 && !start) { // Код, который нужно исполнить started = true; } }); }); 

Just consider one thing: if you expand the screen further, the code will be executed again and again and if it is not needed, the variable started will help.

UPD. Completed the function. Now it can work before resizing when conditions are met. If there is a lot of executable code, then it is possible to make repeating fragments in a separate function.

  • Thank you! I really need the opposite - when it is less than, but this is not important. Will the code work correctly in Chrome and Mozille? - Nikita Shchypylov
  • in all browsers will work - MasterAlex
  • Thanks again - Nikita Shchypylov
  • Sorry, a little not so work. The user will not change the resolution manually, but the function will work if I manually change the screen resolution. What should I do in this case? - Nikita Shchypylov
  • @NikitaShchipilov, that is, it is necessary that the function also work immediately, with the necessary resolution? - MasterAlex