# Stop propagating scroll events when modal dialogs are visible or scrollable popups have focus

**URL:** <https://meta.discourse.org/t/stop-propagating-scroll-events-when-modal-dialogs-are-visible-or-scrollable-popups-have-focus/33264>\
**Category:** UX\
**Created:** [2015 年 9 月 14 日午後 11:25 UTC](https://meta.discourse.org/t/stop-propagating-scroll-events-when-modal-dialogs-are-visible-or-scrollable-popups-have-focus/33264 "2015-09-14T23:25:17Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2015 年 9 月 16 日午前 7:50 UTC](https://meta.discourse.org/t/stop-propagating-scroll-events-when-modal-dialogs-are-visible-or-scrollable-popups-have-focus/33264/7 "2015-09-16T07:50:16Z")

</div>

This works, when the mouse enters the menu, by storing the scrollTop value and then setting the body to `position: fixed` with a top-margin equal to the scrollTop value. When the mouse leaves the menu, `position: fixed` is removed from the body and the body is scrolled to the stored scrollTop value. The downside is that when the mouse enters the menu it can cause the site logo in the header to reappear - I assume that is triggered by the scroll position.

```css
// css
.stop-scrolling {
  position: fixed;
  margin-top: 0;
  width: 100%;
}

```

```js
// menu-panel.js.es6
...
y_offsetWhenScrollingDisabled: 0,

mouseEnter() {
  this.y_offsetWhenScrollingDisabled = $(window).scrollTop();
  $('body').addClass('stop-scrolling').css('margin-top', -this.y_offsetWhenScrollingDisabled);
},

mouseLeave() {
  $('body').removeClass('stop-scrolling').css('margin-top', 0);
  $(window).scrollTop(this.y_offsetWhenScrollingDisabled);
},

```

---

_[View the full topic](https://meta.discourse.org/t/stop-propagating-scroll-events-when-modal-dialogs-are-visible-or-scrollable-popups-have-focus/33264)._
