Issue with click-drag-select in text input field also scrolls parent element, webkit bug or feature?

前端 未结 6 877
一个人的身影
一个人的身影 2021-01-04 13:11

There\'s a weird behavior that I\'ve been experiencing with only the webkit browsers since last year, and it is driving me nuts.

I\'ve tried doing searches on this,

6条回答
  •  走了就别回头了
    2021-01-04 13:34

    The example linked to above gives the basic idea, but it's about an iframe and can be a little confusing to implement on a text input within a div, which is what I (and the original poster) were facing.

    Here's what I ended up doing, using jquery;

    $('body').on('select', '.my_text_input', function(e) {
            $('.div_that_was_moving_weirdly').scrollLeft(0);
             return false;
        });
    

    This is still imperfect, as there will be a jarring scroll over and then jump back, since the select event doesn't seem to kick in until you're done selecting. I tried various events but this is the best I could do.

提交回复
热议问题