# Auto Scroll effect between two strips

**URL:** <https://forum.wixstudio.com/t/auto-scroll-effect-between-two-strips/1627>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [February 10, 2021, 5:39pm UTC](https://forum.wixstudio.com/t/auto-scroll-effect-between-two-strips/1627 "2021-02-10T17:39:23Z")\
**Posts on this page:** 15\
**Page:** 2

<div class="post-metadata">

**Author:** ![edouard](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/edouard/32/26240_2.png) [@edouard](https://forum.wixstudio.com/u/edouard)\
**Post date:** [March 23, 2021, 2:36pm UTC](https://forum.wixstudio.com/t/auto-scroll-effect-between-two-strips/1627/21 "2021-03-23T14:36:17Z")

</div>

@russian-dima[Acceuil | Better&Better | Architecte d’intérieur | Lyon | Matthieu Nicoletti |m6 (betterandbetter.fr)](https://www.betterandbetter.fr/)

I active that for a few min no more

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [March 23, 2021, 2:39pm UTC](https://forum.wixstudio.com/t/auto-scroll-effect-between-two-strips/1627/22 "2021-03-23T14:39:00Z")

</div>

@edouard ok saw it.  
After a few refreshings, now it works fine (i don’t know why).

---

<div class="post-metadata">

**Author:** ![edouard](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/edouard/32/26240_2.png) [@edouard](https://forum.wixstudio.com/u/edouard)\
**Post date:** [March 23, 2021, 2:59pm UTC](https://forum.wixstudio.com/t/auto-scroll-effect-between-two-strips/1627/23 "2021-03-23T14:59:35Z")

</div>

@russian-dima After a few refreshing ? how ? ^^ Is the clearTimeout function not working, and after comprehending the function, it works out ? (actually i published a normal scroll after your message)

---

<div class="post-metadata">

**Author:** ![edouard](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/edouard/32/26240_2.png) [@edouard](https://forum.wixstudio.com/u/edouard)\
**Post date:** [March 23, 2021, 4:17pm UTC](https://forum.wixstudio.com/t/auto-scroll-effect-between-two-strips/1627/24 "2021-03-23T16:17:25Z")

</div>

@russian-dima clearTimeout does’t seem to work ^^

```javascript
var myvar
//scrolls to features
export function toPur_viewportEnter() {
    $w("#Pur").scrollTo()
    clearTimeout(myvar)
}
export function toPur_viewportLeave(event) {
    clearTimeout(myvar)
}

export function Pur_viewportEnter(event) {
    clearTimeout(myvar)
    console.log("pur")
}

export function toHarmonie_viewportEnter() {
    $w("#Harmonie").scrollTo();
    clearTimeout(myvar)
}

export function toHarmonie_viewportLeave(event) {
     clearTimeout(myvar)

}

```

I’ve put a console log, the console log appears, but it drags me to the 'harmony" strip, like it was not clearing

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [March 23, 2021, 5:05pm UTC](https://forum.wixstudio.com/t/auto-scroll-effect-between-two-strips/1627/25 "2021-03-23T17:05:30Z")

</div>

@edouard  
Ok, forget all your attempts and all your current CODE.  
I have played around a little bit, to help you to find a solution. It is still not a perfect working one, but it seems, that is exactly what you want.

I took the elements out of Ahmads example.  
[https://www.wix.com/velo-examples/full-screen-scroll](https://www.wix.com/velo-examples/full-screen-scroll)

And here we go! —\> EXAMPLE: [https://www.media-junkie.com/scrolling-images](https://www.media-junkie.com/scrolling-images)  
After every 3,5 secs a automatic scrolling to the right PIC should be done!

In my example you won’t need any —\> "clearTimeouts"😉

---

<div class="post-metadata">

**Author:** ![edouard](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/edouard/32/26240_2.png) [@edouard](https://forum.wixstudio.com/u/edouard)\
**Post date:** [March 23, 2021, 5:13pm UTC](https://forum.wixstudio.com/t/auto-scroll-effect-between-two-strips/1627/26 "2021-03-23T17:13:16Z")

</div>

@russian-dima How did you do that ? I’m smashing my head against the wall since 1 month on that !

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [March 23, 2021, 5:19pm UTC](https://forum.wixstudio.com/t/auto-scroll-effect-between-two-strips/1627/27 "2021-03-23T17:19:37Z")

</div>

@edouard😁 Just used some →

 ![](https://us1.discourse-cdn.com/wix/original/3X/8/9/8975afbfe336b410091e0265fe9fa320e419f3ba.png)  
and everything was possible 😆.

Ok, before your head is a “mashed potatoe” here the working code…

```javascript
import wixWindow from 'wix-window';

var scrollPosition = 0, scrollInterval = 50

$w.onReady(() => {
    setInterval(show_scrollPosition, scrollInterval);
    setInterval(checkPosition, 3000);
})

function show_scrollPosition() {
    wixWindow.getBoundingRect()
    .then((windowSizeInfo) => {
        scrollPosition = windowSizeInfo.scroll.y;
        console.log("Scroll-Position: ", scrollPosition)
    });
}

function checkPosition() {
 //Defining all Scroll-areas here.....
 if(scrollPosition > 0 && scrollPosition < 500) {$w('#columnStrip1').scrollTo()} //Scroll-area-1
 else if(scrollPosition > 500 && scrollPosition < 1000) {$w('#columnStrip2').scrollTo()} //Scroll-area-2
 else if(scrollPosition > 1000 && scrollPosition < 1500) {$w('#columnStrip3').scrollTo()} //Scroll-area-3
}

```

You can improve this a lot! For example do all the “area-definitions automatically” and not manually in code (but this would be your next CHALLENGE 😉).

Good luck and happy coding!🕶 And perhaps this will be my next BEST-ANSWER (who knows xD).

---

<div class="post-metadata">

**Author:** ![edouard](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/edouard/32/26240_2.png) [@edouard](https://forum.wixstudio.com/u/edouard)\
**Post date:** [March 23, 2021, 5:25pm UTC](https://forum.wixstudio.com/t/auto-scroll-effect-between-two-strips/1627/28 "2021-03-23T17:25:30Z")

</div>

@russian-dima

![](https://us1.discourse-cdn.com/wix/original/3X/2/5/25d611d6738e3553a94868ad0992845f598877f1.gif)

my brain actually :  
Can’t stand this website anymorre, it has been to much work for not a lot… I try your code out right now ! (painful that my work isn’t useful, even if it was almost working ! i’ll put it has hidden before to trash^^)

![](https://us1.discourse-cdn.com/wix/original/3X/8/0/807ff79214c1ccb739ba28a4ff89b87b59b8fe1f.gif)

Yeah, the automated ‘find where to go’ will be a bit challenging !

But i notice a thing … it is based on scroll position ? Cause i’m working … with editor X viewport height ^^ (Part of this freaking challenge)

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [March 23, 2021, 5:27pm UTC](https://forum.wixstudio.com/t/auto-scroll-effect-between-two-strips/1627/29 "2021-03-23T17:27:30Z")

</div>

@edouard  
Tell me if is also working the same way in Editor-X, or not (i do not use Editor-X) so it would be a good info for me.

> > > > damn good xD 😂 😂 🤣

[External Image](https://media4.giphy.com/media/QVP7DawXZitKYg3AX5/giphy.mp4?cid=e2a3cbdedwyz68byp2u5qvccp7u9fwk3x7dd7t9qzgobeebi&rid=giphy.mp4 "Image hosted on another site. Click to open in a new tab.")

How could you add it as a gif-animation ?

---

<div class="post-metadata">

**Author:** ![edouard](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/edouard/32/26240_2.png) [@edouard](https://forum.wixstudio.com/u/edouard)\
**Post date:** [March 23, 2021, 5:56pm UTC](https://forum.wixstudio.com/t/auto-scroll-effect-between-two-strips/1627/30 "2021-03-23T17:56:28Z")

</div>

@russian-dima Ok, well it’s kinda working, but there is a issue with that viewport height ( when i squeeze the screen, the Y scroll change and so it doesn’t work the same anymore !).

With my little brain (actually in lava), how about the idea to sequence scroll position by percentage of viewport ? (dont know if it’s clear)

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [March 23, 2021, 6:01pm UTC](https://forum.wixstudio.com/t/auto-scroll-effect-between-two-strips/1627/31 "2021-03-23T18:01:03Z")

</div>

@edouard  
Yes should be possible to do it in percentage, but it will get more complicated, for sure 😁. Right now, it will be your own way to go. You have to master some chanllenges.

You can update this post, if you have some news on it😉

---

<div class="post-metadata">

**Author:** ![edouard](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/edouard/32/26240_2.png) [@edouard](https://forum.wixstudio.com/u/edouard)\
**Post date:** [March 23, 2021, 6:04pm UTC](https://forum.wixstudio.com/t/auto-scroll-effect-between-two-strips/1627/32 "2021-03-23T18:04:44Z")

</div>

@russian-dima complication with this project, it seems that i made it true already ! I work on it and will be able to share a solution eventually !

![](https://us1.discourse-cdn.com/wix/original/3X/7/e/7eeb94b4e3afe65b864330380eeeac1ca8a17a55.png)

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [March 23, 2021, 6:09pm UTC](https://forum.wixstudio.com/t/auto-scroll-effect-between-two-strips/1627/33 "2021-03-23T18:09:46Z")

</div>

@edouard  
Allright! Good luck & happy coding!

---

<div class="post-metadata">

**Author:** ![edouard](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/edouard/32/26240_2.png) [@edouard](https://forum.wixstudio.com/u/edouard)\
**Post date:** [March 23, 2021, 7:31pm UTC](https://forum.wixstudio.com/t/auto-scroll-effect-between-two-strips/1627/34 "2021-03-23T19:31:01Z")

</div>

@russian-dima  
I’ll make a monument out of your greatness ! It FREAKING WORKS

```javascript

var scrollPosition = 0,
    scrollInterval = 2000,
    windowHeight = 0,
    windowPercent = 1,
    scrollY = 0
$w.onReady(() => {
    setInterval(show_scrollPosition, scrollInterval);
    setInterval(checkPosition, 3000);
    setInterval(() => show_scrollPosition(), scrollInterval);
    $w("#text3").onClick(() => {
        window.openLightbox('Menu');

    })

})

function show_scrollPosition() {
    window.getBoundingRect()
        .then((windowSizeInfo) => {
            windowHeight = windowSizeInfo.window.height
            scrollPosition = windowSizeInfo.scroll.y;
 if (windowHeight > 624) {
                windowPercent = windowHeight / 624

            } else if (windowHeight < 624) {
                windowPercent = windowHeight / 624
            }
            console.log(windowPercent)
            console.log("Scroll-Position: ", scrollPosition)
 //console.log("wH: ", windowHeight)
        });
}

function checkPosition() {

    window.getBoundingRect()
        .then((windowSizeInfo) => {
 //Defining all Scroll-areas here.....
 if (scrollY === windowSizeInfo.scroll.y) {
 if (scrollPosition > 0 && scrollPosition < 500) { $w('#Pur').scrollTo() } //Scroll-area-1
 else if (scrollPosition > 500 * windowPercent && scrollPosition < 1000 * windowPercent) { $w('#Harmonie').scrollTo() } //Scroll-area-2
 else if (scrollPosition > 1000 * windowPercent && scrollPosition < 1500 * windowPercent) { $w('#Loft').scrollTo() } //Scroll-area-3
 else if (scrollPosition > 1500 * windowPercent && scrollPosition < 2000 * windowPercent) { $w('#Elegance').scrollTo() } //Scroll-area-3
 else if (scrollPosition > 2000 * windowPercent && scrollPosition < 2600 * windowPercent) { $w('#Science').scrollTo() } //Scroll-area-3
 else if (scrollPosition > 2600 * windowPercent && scrollPosition < 3200 * windowPercent) { $w('#Betonne').scrollTo() } //Scroll-area-3
 else if (scrollPosition > 3200 * windowPercent && scrollPosition < 4000 * windowPercent) { $w('#Work').scrollTo() } //Scroll-area-3
 else if (scrollPosition > 4000 * windowPercent && scrollPosition < 4500 * windowPercent) { $w('#TopMenu').scrollTo() } //Scroll-area-3
                scrollPosition = windowSizeInfo.scroll.y
            } else if (scrollY !== windowSizeInfo.scroll.y)
                { scrollY = windowSizeInfo.scroll.y}
 
        })
 
 
}

```

```javascript

```

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [March 23, 2021, 7:48pm UTC](https://forum.wixstudio.com/t/auto-scroll-effect-between-two-strips/1627/35 "2021-03-23T19:48:02Z")

</div>

@edouard  
Well done! You are a quick learner! 😜 (looks good) !  
Now take your next challenge —\> automatic area-definitions.

Some hints:  
Try always to create a code which is as flexible, efficient & user-friendly as possible.  
What do i mean?

Example: this part of your code…  
before:

```javascript
var scrollPosition = 0,
    scrollInterval = 2000,
    windowHeight = 0,
    windowPercent = 1,
    scrollY = 0
$w.onReady(() => {
    setInterval(show_scrollPosition, scrollInterval);
    setInterval(checkPosition, 3000);

```

after:

```javascript
//User-Interface------------------------------
var scrollPosition = 0, //Starting Scroll-Position
    scrollInterval = 2000, //Scroll-Position-check after a certain time-period
    checkTimeInterval = 2000, //Position-check after a certain time-period
    windowHeight = 0, // and so on....
    windowPercent = 1,
    scrollY = 0
//User-Interface------------------------------

$w.onReady(() => {
    setInterval(show_scrollPosition, scrollInterval);
    setInterval(checkPosition, checkTimeInterval);

```

The less manual defined variables you have inside the MAIN-CODE-BLOCK —\> the more flexible your CODE will be at the end and everything will be able to be controlled right from the —\> “User-Interface-Section”.

I hope you understand what i want to tell you.

And you also should give some comments into your own code.  
The more your code grows up, the more difficult it will be to understand your own written code.

Good luck & and continue this way & you will become a good coder!

[Previous page](https://forum.wixstudio.com/t/auto-scroll-effect-between-two-strips/1627.md?page=1)
