# Disable page scroll when lightbox is active

**URL:** <https://forum.wixstudio.com/t/disable-page-scroll-when-lightbox-is-active/70461>\
**Category:** Ask the community\
**Tags:** technical-talk, code, question, wix-studio\
**Created:** [April 23, 2025, 3:32pm UTC](https://forum.wixstudio.com/t/disable-page-scroll-when-lightbox-is-active/70461 "2025-04-23T15:32:18Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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:** [April 24, 2025, 7:11pm UTC](https://forum.wixstudio.com/t/disable-page-scroll-when-lightbox-is-active/70461/5 "2025-04-24T19:11:40Z")

</div>

Here, a little present for you…

```javascript
import wixWindowFrontend from 'wix-window-frontend';

$w.onReady(()=> {scrollLock(5000);});

function scrollLock(duration) {
  wixWindowFrontend.getBoundingRect().then((windowSizeInfo) => {
    let scrollX = windowSizeInfo.scroll.x;
    let scrollY = windowSizeInfo.scroll.y;
    const targetScrollX = scrollX;
    const targetScrollY = scrollY;
    let scrollInterval = setInterval(() => {
      wixWindowFrontend.scrollTo(targetScrollX, targetScrollY);
    }, 1);
    setTimeout(() => {
      clearInterval(scrollInterval);
    }, duration);
  });

```

This is my simple **SCROLL-LOCKER** , try to implement it into your own SETUP.

How does it work?

Well, Wix do provide the Window-API …

```javascript
import wixWindowFrontend from 'wix-window-frontend';

```

Which includes 2 modules you need to achieve your wished function!

1. → **wixWindowFrontend.getBoundingRect()**
2. → **wixWindowFrontend.scrollTo()**

And your last ingridient to make your dream come true would be a self generated function, like shown above and your Scroll-locker is already ready to be used.

In this simple example, the locker do lock your scrolling on page for **5 secodns**!  
You can modify this of course and you also can change the code to make the unlocking based on other EVENTS/TRIGGERS, for example when closing the light box you send data back to the page (a simple data-command like {page: unlock}, reading this command on your page directly after closing or opening the lightbox. Oh i think you wanted to lock on Lightbox-open → also no problem!!! → change the LOCKER-CODE!

I did test it only on a plain site (not tested with a lightbox) but out of my point of view = absolutely doable!

You have always to be tricky when working with → WIX \<–, but in most cases there is always a → WORK-AROUND.

**Try to scroll withing first 5 seconds if you can on this site…**

> **[Home | My Site 1](https://velo-ninja.wixstudio.com/my-site-1)**

🙃 😁

**I am sure → YOU CAN’T !**

[https://forum.wixstudio.com/t/how-to-stop-background-page-scrolling-when-the-lightbox-is-active-in-editor-x/9537/3?u=code-ninja](https://forum.wixstudio.com/t/how-to-stop-background-page-scrolling-when-the-lightbox-is-active-in-editor-x/9537/3)

---

_[View the full topic](https://forum.wixstudio.com/t/disable-page-scroll-when-lightbox-is-active/70461)._
