views:

459

answers:

4

I have a modal box window (pop-up) that contains an iframe,
and inside that iframe there's a div that is scrollable.

When I scroll the iframe's inner DIV, and it has reached its top or bottom limit,
the window of the browser itself starts to scroll. this is an unwanted behavior.

I've tried something like this, which kills the main window scroll when
onMouseEnter when mouse enters pop-up box area:

e.preventDefault() is not working as it should for some reason...

$("#popup").mouseenter(function(){
   $(window).bind("scroll", function(e){
       e.preventDefault();
   }); 
}).mouseleave(function(){
    $(window).unbind("scroll");
});
A: 
function stopPropogation(e)
{
    e = e || window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
    if (e.preventDefault) e.preventDefault();
}

This should work.

fasih.ahmed
It didn't. and I don't understand how e.stopPropogation() will work when e.preventDefault() fails to...
vsync
A: 

Apparently, you can set overflow:hidden to prevent scrolling. Not sure how that'd go if the doc is already scrolled. I'm also on a mouseless laptop, so no scrolly wheel testing for me tonight :-) It's probably worth a shot though.

Dan F
i need it to scroll..(long text) the question doesn't revolve around that.
vsync
Yeah, my thinking is set overflow:hidden on the PARENT window. Not the iframe itself. Therefore, parent window is no longer scrollable, but the contents of the iframe are.
Dan F
well, that would make the scrollbar disappear suddenly, and things will shift to the side..not such a great idea
vsync
+2  A: 

Sorry, as far as I'm aware it is impossible to cancel any kind of scroll event.

Both W3 and MSDN say:

Cancelable  No
Bubbles     No

I think you'll have to leave this up to browser authors to fix. Firefox (3.5 on Linux, anyway) seems to have a better behaviour for me: it only scrolls the parent if the child is already at the top/bottom end at the moment you start using the scrollwheel.

bobince
Makes me sad that you're probably right.
vsync
A: 

you can try jscroll pane inside the iframe to replace the default scroll.

http://www.kelvinluck.com/assets/jquery/jScrollPane/jScrollPane.html

I am not sure, but give it a try

adardesign
This is very interesting, thanks. I used this plugin before, its an ugly solution, but a good one for this difficult problem of mine.
vsync