> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/browser/dom/type/window/scroll/lock.md).

# scroll lock

[🔰 JS](/web/js.md) ⟩ [browser](/web/browser.md) ⟩ [DOM](/web/browser/dom.md) ⟩ [types](/web/browser/dom/type.md) ⟩ [Window](/web/browser/dom/type/window.md) ⟩ [scrolling](/web/browser/dom/type/window/scroll.md) ⟩ lock

{% tabs %}
{% tab title="💾 程式" %}

```javascript
function lockScroll(locked=true){
    document.body.style.overflow = locked ? "hidden" : '';
}
```

{% endtab %}

{% tab title="📗 參考" %}

* [ ] JS.info ⟩ [Forbid the scrolling](https://javascript.info/size-and-scroll-window#forbid-the-scrolling)
  {% endtab %}
  {% endtabs %}
