3

Is it possible to disable the ability for the mouse wheel to scroll the page whilst it is inside a certain DIV. That way it can only scroll the div and not the page. JQuery libraries are installed so I imagine it would be something along the lines of .scroll() and stop.pagination but I do not know enough about how to do this.

Any ideas?

Marvellous

RIK
  • 17,723
  • 34
  • 107
  • 185
  • 1
    See this question posted yesterday: http://stackoverflow.com/questions/7571370/jquery-disable-scroll-when-mouse-over-an-absolute-div – David Houde Sep 28 '11 at 15:12

2 Answers2

3

Fixed it.

$('.scrollable').mouseenter(function(){
                    $('body').css('overflow', 'hidden');
                });
                $('.scrollable').mouseleave(function(){
                    $('body').css('overflow', 'auto');
                });
RIK
  • 17,723
  • 34
  • 107
  • 185
  • I have a very strong gut feeling that this might not work as intended if the viewport in not scrolled to top when this happens. Am I wrong? – ANeves thinks SE is evil Sep 28 '11 at 15:30
  • @ANeves Seams to be working perfectly. I haven't checked in all browsers yet though – RIK Sep 28 '11 at 15:32
  • Blast but on fixed scrollbar, the scrollbars disappear – RIK Sep 28 '11 at 15:34
  • Nevermind other browsers, and thanks for checking for me. I was thinking that when making `overflow: hidden;` for the body the body's scroll would be reset to top before the scrollbar was removed. Seems it is not the case. – ANeves thinks SE is evil Sep 28 '11 at 15:35
  • No but I did notice that when the scrollbar disappears if you have centre or rightward aligned document, the content shifts by the width of the scrollbars to re align. Which is annoying when using it. Another way has been outlined using the scroll() function – RIK Sep 28 '11 at 15:39
0

Pure css.

For the div you want to scroll:

#divId {
    overflow: scroll;
    height: someHeight;
}
Naftali aka Neal
  • 138,754
  • 36
  • 231
  • 295
  • I know that bit. It would appear through that the page is trying to scroll too – RIK Sep 28 '11 at 15:02
  • You are in fact correct, but due to my reinvention of the sculling system on the page pure CSS is not fixing it. Thanks – RIK Sep 28 '11 at 15:09
  • @RobinKnight `reinvention of the sculling system`? what does that mean? – Naftali aka Neal Sep 28 '11 at 15:11
  • The scrolling system. I appear to have a predictive text on. It is a heavily modified series of plugins that ensure that the scrolling system works a smoothly as possible on all platforms including mobile – RIK Sep 28 '11 at 15:14