开发者

InputTextarea autoscroll behavior

开发者 https://www.devze.com 2023-03-09 01:28 出处:网络
I have a inputTextarea that I refresh using PrimeFaces\' AJAX poll. When the inputTextarea is refreshed, a lot of new text will be displayed. However, it will always jump to the first line after refr

I have a inputTextarea that I refresh using PrimeFaces' AJAX poll.

When the inputTextarea is refreshed, a lot of new text will be displayed. However, it will always jump to the first line after refresh. If the user wants to scroll down and the poll/refresh happens, it will jump to the top anyway.

Is there anything I can do to prevent the jumping to the top (or better: prevent jumping at all)? If not, can I make the inputTextarea stay on the bottom at least? (Since the new lin开发者_StackOverflow中文版es will be appended to the bottom.)

I'm using JSF 2 (MyFaces), Tomahawk and PrimeFaces.


Use JavaScript. Include this script below the <h:inputTextarea> in the portion which is been updated by <p:poll> or in a function when the component supports oncomplete (not sure as I don't have recent PF documentation).

var textarea = document.getElementById("clientIdOfTheTextarea");
textarea.scrollTop = textarea.scrollHeight; // Scrolls to bottom.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号