Here is my code snippet:
If i click and drag over the input text field, I get the div with overflow:hidden scrolling as it would do with overflow:auto. If I set overflow:hidden on a div, I want the scrolling to be locked as other browsers do.
The curious thing is that if I set padding:0px on the input field, the issue on Chrome does not occur anymore.
Is it a Google Chrome bug? Any workaround to make it work without the use of Javascript?
EDIT: This behaviour happens on Safari 5 too. Maybe it is a Webkit issue.
Here's what fixed it for me:
Thanks to https://stackoverflow.com/users/498031/vken for pointing this out over at this similar question: Issue with click-drag-select in text input field also scrolls parent element, webkit bug or feature?
UPDATE 2013-11:
pointer-events:none
fixes the issue but comes with numerous disadvantages. Best workaround for the issue is actually to make sure you have no overflowing content as in "the content of theoverflow:hidden
container is not bigger than said container. If you want to scroll content in via JavaScript, give it width&height=0 as long as it's hidden and resize it only right before moving it in (easily done with keyframe-animations or timed transitions)IMPORTANT: I encountered a weird case with a customized
<input type=file>
field in Chrome which should not have caused any overflow-issues as I resized it via CSS - the dev-tools confirmed that, BUT: After taking a look at the Shadow-DOM I realized that Chrome's own "buttons" overflowed the actual input-field and therefore caused the entire container to be bigger.How to show Shadow-DOM: If things look right and it still is an issue go to Chrome Dev-Tools, click on the Settings-Button in the lower right corner. On the "General"-tab in section "Elements" is the option to enable "Show Shadow DOM". This will give you the entire picture of what's going on... Though most of the time it just adds another layer of complexity, here it's really helpful!
I tried tiffon's solution using JQuery but couldn't get it to work with multiple fields, mouseup wouldn't fire after I had set pointer-events to none.
So, setting the input 'pointer-events' to none solves the problem of scrolling into hidden content, but it prevents the user from focusing the field using mouse events. But I noticed that clicking the label would still work to focus the field.
So I made this workaround that works cause all my fields are nested inside div's. Basically clicking the field doesn't focus it but still bubbles the event to it's parent:
Problem is it doesn't let you select the text inside the field unless you use the keyboard arrow keys.
Set scrollLeft and/or scrollTop to 0 in the "onscroll" event, this will disable scrolling:
I ran into this, too. So far, the thing I've gotten to work the best is using
pointer-events:none;
. The only way I could get it to be applied was to set thedisplay: none;
. Otherwise it was ignored, so there's a brief blink.http://jsfiddle.net/7CuBV/21/