Scroll an overflowing div by scrolling anywhere on the page

I’d like to trigger scrolling of a div with overflowing content by scrolling anywhere on the page, not just by moving the mouse and clicking within the div. Also, i’d like to hide the div’s scrollbar such that only the page’s scrollbar is visible.

Preferably the solution would be CSS-based but a JS solution would work too.

  • How to create a highlight an image when double clicked?
  • How to use pagination on HTML tables?
  • jQuery.height() behaves differently in WebKit and Firefox when using box-sizing:border-box
  • HTML, CSS & JS Animate Multiple Progress bars
  • Why does Google Chrome 9 not show images from Amazon S3?
  • Is there any way to invert every color set within a parent div?
  • here’s my jsfiddle that demonstrates the problem: http://jsfiddle.net/trpeters1/RMZsX/8/

    I’d copy the code here but there I put a bunch of filler text to trigger the scrollbars.

    For you reference though, the name of the internal div I’d like to scroll on scrolling the page has an id="scrollMeToo".

  • How to shake login form on error
  • jQuery .animate() sets display:none, how to avoid?
  • Javascript regex to detect CSS code inside a string?
  • jQuery mouseenter is just flickering the img
  • Jquery class name not showing properly
  • jQuery scrollTop and focus on element
  • 2 Solutions collect form web for “Scroll an overflowing div by scrolling anywhere on the page”

    var curScroll = 0;
    
    $(window).bind('mousewheel DOMMouseScroll', function(e){
        var evt = window.event || e;
        var delta = evt.detail? evt.detail*(-120) : evt.wheelDelta;
        if(delta < 0) {
            //scroll down
            curScroll += 10;
        }
        else {
            //scroll up
            curScroll -= 10;
        }
        $('#scrollMeToo').scrollTop(curScroll);
        return true;
    }); 
    #scrollMeToo {
        height: 200px;
        width:150px;
        overflow: auto;
        position: relative;
        overflow-y: hidden;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
                 <p>
                Ad leggings keytar, brunch id art party dolor labore. Pitchfork yr enim lo-fi before they sold out qui. Tumblr farm-to-table bicycle rights whatever. Anim keffiyeh carles cardigan. Velit seitan mcsweeney's photo booth 3 wolf moon irure. Cosby sweater lomo jean shorts, williamsburg hoodie minim qui you probably haven't heard of them et cardigan trust fund culpa biodiesel wes anderson aesthetic. Nihil tattooed accusamus, cred irony biodiesel keffiyeh artisan ullamco consequat.
                </p>
                 <p>
                Ad leggings keytar, brunch id art party dolor labore. Pitchfork yr enim lo-fi before they sold out qui. Tumblr farm-to-table bicycle rights whatever. Anim keffiyeh carles cardigan. Velit seitan mcsweeney's photo booth 3 wolf moon irure. Cosby sweater lomo jean shorts, williamsburg hoodie minim qui you probably haven't heard of them et cardigan trust fund culpa biodiesel wes anderson aesthetic. Nihil tattooed accusamus, cred irony biodiesel keffiyeh artisan ullamco consequat.
                </p>
                 <p>
                Ad leggings keytar, brunch id art party dolor labore. Pitchfork yr enim lo-fi before they sold out qui. Tumblr farm-to-table bicycle rights whatever. Anim keffiyeh carles cardigan. Velit seitan mcsweeney's photo booth 3 wolf moon irure. Cosby sweater lomo jean shorts, williamsburg hoodie minim qui you probably haven't heard of them et cardigan trust fund culpa biodiesel wes anderson aesthetic. Nihil tattooed accusamus, cred irony biodiesel keffiyeh artisan ullamco consequat.
                </p>
    <hr>
    
    
    <div id="scrollMeToo">
                <h4 id="fat">@fat</h4>
                <p>
                Ad leggings keytar, brunch id art party dolor labore. Pitchfork yr enim lo-fi before they sold out qui. Tumblr farm-to-table bicycle rights whatever. Anim keffiyeh carles cardigan. Velit seitan mcsweeney's photo booth 3 wolf moon irure. Cosby sweater lomo jean shorts, williamsburg hoodie minim qui you probably haven't heard of them et cardigan trust fund culpa biodiesel wes anderson aesthetic. Nihil tattooed accusamus, cred irony biodiesel keffiyeh artisan ullamco consequat.
                </p>
                <h4 id="mdo">@mdo</h4>
                <p>
                Veniam marfa mustache skateboard, adipisicing fugiat velit pitchfork beard. Freegan beard aliqua cupidatat mcsweeney's vero. Cupidatat four loko nisi, ea helvetica nulla carles. Tattooed cosby sweater food truck, mcsweeney's quis non freegan vinyl. Lo-fi wes anderson +1 sartorial. Carles non aesthetic exercitation quis gentrify. Brooklyn adipisicing craft beer vice keytar deserunt.
                </p>
                <h4 id="one">one</h4>
                <p>
                Occaecat commodo aliqua delectus. Fap craft beer deserunt skateboard ea. Lomo bicycle rights adipisicing banh mi, velit ea sunt next level locavore single-origin coffee in magna veniam. High life id vinyl, echo park consequat quis aliquip banh mi pitchfork. Vero VHS est adipisicing. Consectetur nisi DIY minim messenger bag. Cred ex in, sustainable delectus consectetur fanny pack iphone.
                </p>
                <h4 id="two">two</h4>
                <p>
                In incididunt echo park, officia deserunt mcsweeney's proident master cleanse thundercats sapiente veniam. Excepteur VHS elit, proident shoreditch +1 biodiesel laborum craft beer. Single-origin coffee wayfarers irure four loko, cupidatat terry richardson master cleanse. Assumenda you probably haven't heard of them art party fanny pack, tattooed nulla cardigan tempor ad. Proident wolf nesciunt sartorial keffiyeh eu banh mi sustainable. Elit wolf voluptate, lo-fi ea portland before they sold out four loko. Locavore enim nostrud mlkshk brooklyn nesciunt.
                </p>
                <h4 id="three">three</h4>
                <p>
                Ad leggings keytar, brunch id art party dolor labore. Pitchfork yr enim lo-fi before they sold out qui. Tumblr farm-to-table bicycle rights whatever. Anim keffiyeh carles cardigan. Velit seitan mcsweeney's photo booth 3 wolf moon irure. Cosby sweater lomo jean shorts, williamsburg hoodie minim qui you probably haven't heard of them et cardigan trust fund culpa biodiesel wes anderson aesthetic. Nihil tattooed accusamus, cred irony biodiesel keffiyeh artisan ullamco consequat.
                </p>
                <p>Keytar twee blog, culpa messenger bag marfa whatever delectus food truck. Sapiente synth id assumenda. Locavore sed helvetica cliche irony, thundercats you probably haven't heard of them consequat hoodie gluten-free lo-fi fap aliquip. Labore elit placeat before they sold out, terry richardson proident brunch nesciunt quis cosby sweater pariatur keffiyeh ut helvetica artisan. Cardigan craft beer seitan readymade velit. VHS chambray laboris tempor veniam. Anim mollit minim commodo ullamco thundercats.
                </p>
    </div>

    you can set overflow:hidden for div .and set css to deselection div content.

     var clicking = false;
     var position;
     var scrollpos;
    $(window).mousedown(function(e){
        clicking=true;
        position = e.pageY;
    });
    $(window).mouseup(function(){
          clicking = false;
    })
    $(window).mousemove(function(e){
          if(clicking == false) 
                return;
          scrollpos=$('#scrollMeToo').scrollTop();
          $('#scrollMeToo').scrollTop(scrollpos + (e.pageY-position)) ;
    })