Ho risolto inserendo

var fromTop=txtarea.scrollTop;

e alla fine

txtarea.scrollTop=fromTop;