简体   繁体   中英

Prevent textarea from scrolling vertically

I am using https://github.com/ultimatedelman/autogrow so my textarea grows as the user enters text. It works great, but when you get the bottom of the text area, it scrolls up before expanding, causing an unsightly jumping effect. This is visible in the author's demo as well (click on "Interactive Demo" on the above page since Stack Overflow won't let me post a jsfiddle.net here unaccompanied by code).

Is there some way to suppress vertical scrolling completely to avoid this jumping effect? I tried:

textarea.scroll(function(e) {
  e.preventDefault();
});

That doesn't seem to prevent the scrolling from occurring though.

Just discovered http://www.jacklmoore.com/autosize/ . It is way slicker than the plugin I mentioned in the question. Notably it has no problem at all with jumping or gittering as it resizes. So this seem like the right answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM