简体   繁体   中英

Can I maintain textarea scroll position after editing text with javascript?

I have something like a Text editor similar to the one used here (WMD Markdown Editor). The problem I have is after modifying text with JS, the textarea scrolls back to the top ...

http://jsfiddle.net/qTRhu/1/

http://screenr.com/7uz

As I remember this is an issue with one browser particularly (firefox?). You need to save and restore the scrollbar position and (depending on your design) the selected text.

    var scrollTop = txtarea.scrollTop;

......

    txtarea.scrollTop = scrollTop;

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