Pausing code for a set amount of time

I’d like to pause my whole page’s code until a scroll action (I used the scrollTo function) is finished or just for a set amount of time (this is a backup option but would work too).

Context: I have a button that scrolls the page to the bottom, however, since I have quite a lot of viewport enter/leave code, the page will lag out super hard, since it’s trying to execute a bunch of code in a very short amount of time. (ironically I have this code in place to optimize the page’s performance, which it does pretty well, except for in this case, which is why I’m here) So what I want to have happen is that all other code is temporarily paused until the scroll is finished (or for a set amount of time).

I’ve looked at the setTimeout function, but I don’t think it can do what I need it to, since it only “pauses” the code inside of its brackets, which isn’t going to work in my case.

Here’s what I essentially want to do:
if(button press){
scroll page to bottom
delay (until scroll is finished/for a set amount of time) - this will cause the code to get “hung up” here for a set amount of time, which means no other code is executed
}

Thanks in advance for any help.

Hello, without to read all your description and just to answer to your TOPIC-HEADER —> setTimeout() will be what you need, i think.

setTimeout(()=>{},2500)  //2500milliseconds = 2,5sec.

Everything, what is between the → { } will be your CODE, which will start after the given delay-time.

Ok, i was to fast, just have seen right now, that you already tried to use this one.
Ok, then i have to read your description xDDDD😁

No worries. Do you have any ideas?

I am already searching for a solution :wink:.
One question.
Why do you have so many onEnter/Leave-code parts ?
Do you have a one-pager with a ton of anchors?

basically my page is a collection of a bunch of home videos with galleries as previews. I have the galleries auto play and I use the onEnter/Leave to play/pause them as they come into/out of view, because having all of them playing was causing quite a lot of lag. The issue with this is that as the page scrolls down (pretty fast), when you press the button, it tries to play and pause each gallery which causes lag as well.

Edit: and they are split up across multiple pages (sorted by categories), but they’re still enough per page to become overwhelming.

Could you show the website, where i can take a look on the website-structure?
Perhaps there are other ways to find a solution?

Uhhh… I’m not comfortable putting the link out there, as some of the info on the website is semi personal (and IDK if everyone that ever shows up in the videos is ok with me sharing this with people other than friends&family), but I could send you some screenshots.

Ok, screenshots are ok


Here are a few and basically the page just keeps on going like this. In the menu, when you hover over “Videos” it will show you the different categories, which bring you the the different pages I mentioned earlier.

The button I’m talking about is the green button at the top of the page which brings you to the bottom (where the newest video would be added). Really, the lag is not a huge deal since it immediately goes away once the page is done scrolling, but I’m a perfectionist in that regard.

Also, I’m aware that the page currently looks terrible, I’m working on making some small visual fixes to make it look better. (for example the space between the galleries and the title, idk how that happened, this page is relatively old). I’d also like to keep the list style, although I know it doesn’t look amazing and probably causes a few issues, because it organizes the videos in a logical way.

Go crazy xD

Ok, now i understand your issue. Have to think for a while :grin:
But i have already a question, without really to start finding a solution to this issue.

Why not put the newest video always on TOP ?

(for example the space between the galleries and the title, idk how that happened)
This is a Wix-related problem. I know what you mean. The grow of spacing with every publication of the site. I had/have also to struggle with that sometimes.

Oh, that’s interesting. I knew that I didn’t make those spaces that big lol.

The reason I don’t put the newest video on top is basically laziness. I could definitely do that, but at the time that I started the website I didn’t think of it and just put all of them at the bottom. This continued until now, and now i’m too lazy to flip the order. So some time back I realized this issue and just put a button at the top. :laughing: If you’re looking for a definition of a patch job, it’s right here.

Edit: I doubt this is possible, but… each video (title, gallery, and buttons) is grouped, so if there’s a way to flip the order of items on the page, that might work.

Ok, i think i will give you tomorrow a first proposed solution …to be continued…

Here you can see the first try, which is still not completed, i will complete it tomorrow, but now it is time to go to bed :grin:.

You can see here a repeater, which loads videos by geting URL’s from a DATABSE. I do not know how you are loading your videos, but with this technique you are able to sort them like you want (by DATE or by Name for example).
So you could also change the order how you want.
And i also know why you may have needed those spaces .:grin:

Like i asume, you just put video after video, by your own into your page, and let it looking like a list right?

Well here an example for you…
https://russian-dima.wixsite.com/meinewebsite/blank-21

There are still a few issues which i will eleminate tomorrow.

What you could do till tomorrow, is to create a little database with following COLUMNs ( title <---- first STANDARD-COLUMN / Video-Url / Date / Group).

Fill this database with about 5-10 items.

And perhaps, all these issues here…

Oh, that’s interesting. I knew that I didn’t make those spaces that big lol.

The reason I don’t put the newest video on top is basically laziness. I could definitely do that, but at the time that I started the website I didn’t think of it and just put all of them at the bottom. This continued until now, and now i’m too lazy to flip the order. So some time back I realized this issue and just put a button at the top. :laughing: If you’re looking for a definition of a patch job, it’s right here.

Edit: I doubt this is possible, but… each video (title, gallery, and buttons) is grouped, so if there’s a way to flip the order of items on the page, that might work.
Could be eleminated tomorrow :wink:

Currently I view/load my videos via a lightbox. So I have a lightbox set up with a text box (for the title) and a video player (for the video). The video player uses a string as its url, and the text box uses a different string which will contain the title. Back on the page with all of the videos and buttons (in the screenshots earlier), I have code that checks if the each button was pressed, and fills in the strings accordingly. This allows me to have one lightbox for every single video. The videos are stored on youtube btw.

As for your solution, it sounds like a good way to do it, and it would reduce the work needed to add a new video, but it does look to be a decent amount of work to convert the current website to this way, as it’s essentially a complete rework, and I honestly don’t really feel like putting in this much work, nor do I have the time. I think I will just deal with having lag on the scrolling button for now😂. However, if I do ever plan on re-working this website, I’ll use your method.

Hello rts23,

back again to your issue :grin: ,sorry it took me more time to find a good solution then i thought. And now after 2-days of brainstorming, testing and a lot of analyses, i got a cool solution.

This solution works without any “ANCHORS”, hided “STRIPES” or other unnasscessary stuff. :sunglasses: It works fast and wihout large loading-times.

And it is connected to a database of course.

You can see the example here.
https://russian-dima.wixsite.com/meinewebsite/blank-21

So if you are a really “PERFECTIONIST” :grin: … then you know what to do :wink:

And of course you can expand your project and add LIGHTBOXES into the project and so on.

Just think about that —> no more manual video-inputs.
Just adding “TITLE” + “VIDEO-URL” + “DESCRIPTION” … and so on, into the database and the rest is magic :laughing:

Use currentTime .It will pause video after certain amount of time

if ( $w ( ‘#videoPlayer1’ ). currentTime === 7 )
{
$w ( ‘#videoPlayer1’ ). pause ();

    }