嘿,我正在制作一個聊天機器人,但我希望當您按 Enter 或單擊按鈕時,div 滾動到底部,因為當您與機器人聊天時,您需要每次都向下滾動。我有一個函數,但滾動必須在talk()函數中。這是模板代碼<template> <div class="container"> <div class="container max"> <div class="container con"> <div class="row ml-0 mt-3"> <p>{{this.know.welkom}}</p> </div> <p id="chatLog" class="chatLog font-weight-bold"></p><br> </div> </div> <div class="row mt-4"> <div class="col"> <input id="userBox" class="inputChat" type="text" @keyup.enter="talk()" v-model="msg" required> </div> <div type="submit" value="Send" class="btn btn-primary mt-2 ml-2" @click="talk()">Send<img class="sendIcon" src="@/assets/icons/send.png"></div> </div> </div></template>這是我的腳本import json from './info.json';export default { data() { return { title: 'Chat bot', test: this.json, know: { 'welkom' : '??Welcome I will help you to answer your questions. If you want more info type "help".??', 'help' : 'These are the questions that can be answerd: <br>' + '1?? how do you login <br>' + '2?? how do you register <br>' + '3?? how to add a internship <br>' + '4?? edit a internship <br>' + '5?? who are you',我在 之間使用了滾動高度this.msg = '';并 console.log(this.msg);看到talk() function
1 回答

瀟湘沐
TA貢獻1816條經驗 獲得超6個贊
要滾動到 #chatLog div 的底部,只需執行以下操作:
const chatLogDiv = document.getElementById('chatLog') chatLogDiv.scrollTop = chatLogDiv.scrollHeight
- 1 回答
- 0 關注
- 207 瀏覽
添加回答
舉報
0/150
提交
取消