Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7495223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:00:06+00:00 2026-05-29T18:00:06+00:00

I have a vertically-scrolling div within a page that also scrolls vertically. When the

  • 0

I have a vertically-scrolling div within a page that also scrolls vertically.

When the child div is scrolled with the mouse wheel and reaches the top or bottom of the scroll bar, the page (body) begins to scroll. While the mouse is over the child div, I’d like the page (body) scroll to be locked.

This SO post (scroll down to the selected answer) demonstrates the problem well.

This SO question is essentially the same as mine, but the selected answer causes my page contents to noticeably shift horizontally as the scrollbar disappears and reappears.

I thought there might be a solution that leverages event.stopPropagation(), but couldn’t get anything to work. In ActionScript, this kind of thing would be solved by placing a mousewheel handler on the child div that calls stopPropagation() on the event before it reaches the body element. Since JS and AS are both ECMAScript languages, I thought the concept might translate, but it didn’t seem to work.

Is there a solution that keeps my page contents from shifting around? Most likely using stopPropagation rather than a CSS fix? JQuery answers are welcome as is pure JS.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T18:00:08+00:00Added an answer on May 29, 2026 at 6:00 pm

    here’s what i ended up with. very similar to @mrtsherman’s answer here, only pure JS events instead of jQuery. i still used jQuery for selecting and moving the child div around, though.

    // earlier, i have code that references my child div, as childDiv
    
    function disableWindowScroll () {
        if (window.addEventListener) {
            window.addEventListener("DOMMouseScroll", onChildMouseWheel, false);
        }
        window.onmousewheel = document.onmousewheel = onChildMouseWheel;
    }
    
    function enableWindowScroll () {
        if (window.removeEventListener) {
            window.removeEventListener("DOMMouseScroll", onArticleMouseWheel, false);
        }
        window.onmousewheel = document.onmousewheel = null;
    }
    
    function onChildMouseWheel (event) {
        var scrollTgt = 0;
        event = window.event || event;
        if (event.detail) {
            scrollTgt = -40 * event.detail;
        } else {
            scrollTgt = event.wheelDeltaY;
        }
    
        if (scrollTgt) {
            preventDefault(event);
            $(childDiv).scrollTop($(childDiv).scrollTop() - scrollTgt);
        }
    }
    
    function preventDefault (event) {
        event = event || window.event;
        if (event.preventDefault) {
            event.preventDefault();
        }
        event.returnValue = false;
    }
    

    i’ve noticed the scrolling doesn’t match normal scrolling exactly; it seems to scroll a bit faster than without this code. i assume i can fix by knocking down wheelDeltaY a bit, but it’s odd that it would be reported differently by javascript than it’s actually implemented by the browser…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a longish form that scrolls vertically and also allows editing records. When
I have two horizontally scrolling UIScrollViews stacked vertically on top of each other within
I have a div that is scrolling vertically. I, however, really want it to
I currently have a GridView scrolling vertically, and everything works fine. But now that
I have sever JPanels which have to be ordered vertically. For that I want
How to vertically align the text in a floated div? For example: I have
I'm doing custom drawing in datagridview cells and I have items that can vertically
In silverlight 2.0. I have some content that i want to scroll vertically and
I have a div with WIDTH 100% and position fixed on the top of
I have a div.scroll_fixed with the following CSS .scroll_fixed { position:absolute top:210px } .scroll_fixed.fixed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.