function clickAiSendDescription() { $('#id-listing-settings').on('click', '.sell-description-click-for-ai', function (e) { let url = $(this).data('ai-url'); let head_box_div = $('#id-listing-settings').find('#textarea-edit'); let domain_id = $(this).data('domain-id'); let data = {}; data.send_ai = 'send_ai'; data.domain_id = domain_id; data.question_id = 1; data.question_style_id = -1; let ai_send_div = $(this).parent().find('.ai-sends-icon'); let loading_gif_blue_icon = $("input[name='ai-loading-gif-blue-icon']").val(); ai_send_div.html('<img src="' + loading_gif_blue_icon + '" class = "loading-icon-img" border="0" >') $(this).css("pointer-events", 'none'); $.ajax({ url: url, type: 'POST', data: data }).done(function (responseData) { let json = JSON.parse(responseData); if (json.code == '0') { let text = $(json.message).text(); printTextVerbatim(head_box_div.children(), text); } }) e.stopPropagation(); }) } function printTextVerbatim(text_div, aiText) { text_div.html(''); let progress = 0; let timer = function () { let current = aiText.substr(progress, 1); if (current == '<') { progress = aiText.indexOf('>', progress) + 1 } else { progress += 6 } text_div.html(aiText.substring(0, progress)); if (progress >= aiText.length - 1) { clearTimeout(timer); } else { setTimeout(timer, 60); } }; setTimeout(timer, 70); }. 这个代码怎样可以使文本域随着文本向下滚动
时间: 2024-02-14 08:13:15 浏览: 265
pwb-for-heroku:一个使用property-web-builder gem的Rails网站,并准备将其部署到heroku
可以修改printTextVerbatim函数,在text_div.html(aiText.substring(0, progress))后添加scrollTo函数,将滚动条滚动到文本最底部。具体代码如下:
```
function printTextVerbatim(text_div, aiText) {
text_div.html('');
let progress = 0;
let timer = function () {
let current = aiText.substr(progress, 1);
if (current == '<') {
progress = aiText.indexOf('>', progress) + 1
} else {
progress += 6
}
text_div.html(aiText.substring(0, progress));
text_div.scrollTop(text_div[0].scrollHeight); // 添加滚动条滚动到文本最底部的代码
if (progress >= aiText.length - 1) {
clearTimeout(timer);
} else {
setTimeout(timer, 60);
}
};
setTimeout(timer, 70);
}
```
阅读全文