vue窗口內(nèi)容滾動(dòng)到底部實(shí)現(xiàn)過(guò)程
vue窗口內(nèi)容滾動(dòng)到底部
onMounted(() => {
scrollToBottom()
})
// 滾動(dòng)到底部方法
const scrollToBottom = () => {
// 獲取聊天窗口容器
let chatRoom: any = document.querySelector(".chat-content");
// 滾動(dòng)到容器底部
chatRoom.scrollTop = chatRoom.scrollHeight;
}效果

聊天窗口代碼
<template>
<div class="chat">
<div class="left">
<div class="top">
<ClientOnly>
<el-input v-model="search" style="width: 240px;" placeholder="搜索聯(lián)系人" :suffix-icon="Search" />
</ClientOnly>
</div>
<div class="ul">
<div class="li" v-for="item, i in 5" :key="i">
<div class="img">
<img src="/assets/images/head/user.jpg" alt="">
</div>
<div class="content">
<div class="name">前端</div>
<div class="text text_ov1">大佬,請(qǐng)問(wèn)這個(gè)怎么寫(xiě)?看到請(qǐng)回復(fù)一下,謝謝</div>
</div>
<div class="tiem">
18:00
</div>
</div>
</div>
</div>
<div class="right">
<div class="chat-name">前端</div>
<!-- 聊天內(nèi)容 -->
<div class="chat-content">
<!-- 收到的 -->
<div class="chat-item">
<div class="chat-img">
<img src="/assets/images/head/user.jpg" alt="">
</div>
<div class="chat-text">
大佬,請(qǐng)問(wèn)這個(gè)怎么寫(xiě)?看到請(qǐng)回復(fù)一下,謝謝!大佬,請(qǐng)問(wèn)這個(gè)怎么寫(xiě)?看到請(qǐng)回復(fù)一下,謝謝大佬,請(qǐng)問(wèn)這個(gè)怎么寫(xiě)?看到請(qǐng)回復(fù)一下,謝謝大佬,請(qǐng)問(wèn)這個(gè)怎么寫(xiě)?看到請(qǐng)回復(fù)一下,謝謝
</div>
</div>
<!-- 發(fā)送的 -->
<div class="my_chat-item" v-for="item, i in 10" :key="i">
<div class="chat-img">
<img src="/assets/images/head/user.jpg" alt="">
</div>
<div class="chat-text">
大佬,請(qǐng)問(wèn)這個(gè)怎么寫(xiě)?看到請(qǐng)回復(fù)一下,謝謝!大佬,請(qǐng)問(wèn)這個(gè)怎么寫(xiě)?看到請(qǐng)回復(fù)一下,謝謝大佬,請(qǐng)問(wèn)這個(gè)怎么寫(xiě)?看到請(qǐng)回復(fù)一下,謝謝大佬,請(qǐng)問(wèn)這個(gè)怎么寫(xiě)?看到請(qǐng)回復(fù)一下,謝謝
</div>
</div>
</div>
<!-- 輸入框 -->
<div class="chat-input">
<div class="rest">
<div class="ul">
<div class="li">
<i class="iconfont icon-smile"></i>
</div>
<div class="li">
<i class="iconfont icon-tupian"></i>
</div>
</div>
<div class="publish">發(fā)送</div>
</div>
<ClientOnly>
<el-input type="textarea" resize="none" :autosize="{ minRows: 6, maxRows: 6 }" maxlength="500" show-word-limit
placeholder="" v-model="message">
</el-input>
</ClientOnly>
</div>
</div>
</div>
</template><script setup lang="ts">
import { Search } from '@element-plus/icons'
let search = ref("");
let message = ref("");
onMounted(() => {
scrollToBottom()
})
// 滾動(dòng)到底部方法
const scrollToBottom = () => {
// 獲取聊天窗口容器
let chatRoom: any = document.querySelector(".chat-content");
// 滾動(dòng)到容器底部
chatRoom.scrollTop = chatRoom.scrollHeight;
}
</script>
<style scoped lang="scss">
.chat {
margin-left: 22px;
width: 1030px;
border-radius: 12px;
background: #ffffff;
display: flex;
.left {
padding-top: 10px;
border-right: 1px solid #dddddd;
width: 255px;
.top {
display: flex;
justify-content: center;
align-items: center;
height: 55px;
}
.ul {
.li {
padding: 15px;
background-color: #fff;
height: 66px;
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid #E4E7ED;
cursor: pointer;
&:hover {
background: #F1F6FF;
}
.img {
width: 42px;
height: 42px;
overflow: hidden;
border-radius: 50%;
margin-right: 10px;
img {
width: 100%;
}
}
div.content {
width: 60%;
div.name {
font-size: 14px;
color: #303133;
}
div.text {
margin-top: 2px;
font-size: 12px;
color: #3D3D3D;
}
}
div.tiem {
font-size: 12px;
color: #3D3D3D;
}
}
}
}
.right {
padding-top: 10px;
flex: 1;
.chat-name {
border-bottom: 1px solid #dddddd;
height: 55px;
line-height: 55px;
padding-left: 20px;
}
/**聊天框*/
div.chat-content {
overflow-y: scroll;
height: 500px;
padding: 20px 10px;
&::-webkit-scrollbar {
/**display: none;*/
width: 5px !important;
}
/**我接收的*/
div.chat-item {
display: flex;
margin-top: 20px;
div.chat-img {
width: 48px;
height: 48px;
border-radius: 50%;
overflow: hidden;
margin-right: 5px;
img {
width: 100%;
}
}
div.chat-text {
background: #EEEEEE;
border-radius: 6px;
padding: 10px;
margin-right: 200px;
font-size: 14px;
color: #3D3D3D;
line-height: 20px;
flex: 1;
}
}
/**我發(fā)送的*/
div.my_chat-item {
display: flex;
flex-direction: row-reverse;
margin-top: 20px;
div.chat-img {
width: 48px;
height: 48px;
border-radius: 50%;
overflow: hidden;
margin-left: 5px;
img {
width: 100%;
}
}
div.chat-text {
background: #EEEEEE;
border-radius: 6px;
padding: 10px;
flex: 1;
margin-left: 200px;
font-size: 14px;
color: #3D3D3D;
line-height: 20px;
}
}
}
.chat-input {
height: 30%;
border-top: 1px solid #dddddd;
.rest {
display: flex;
justify-content: space-between;
align-items: center;
padding: 5px 20px;
.ul {
display: flex;
.li {
margin-right: 20px;
i {
color: #3D3D3D;
cursor: pointer;
}
}
}
}
// 清除文本域邊框
:deep(.el-textarea__inner) {
box-shadow: 0 0 0 0px;
}
:deep(.el-textarea__inner:hover) {
box-shadow: 0 0 0 0px;
}
:deep(.el-textarea__inner:focus) {
box-shadow: 0 0 0 0px;
}
.publish {
cursor: pointer;
width: 74px;
height: 28px;
border-radius: 14px;
text-align: center;
line-height: 28px;
background: #fff;
color: #888888;
font-size: 14px;
border: 1px solid #888888;
&:hover {
background: #C4302C;
color: #fff;
border: 1px solid #ffffff00;
}
}
}
}
}
</style>總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- vue實(shí)現(xiàn)滾動(dòng)條滾動(dòng)到底部時(shí)發(fā)送請(qǐng)求獲取數(shù)據(jù)方式
- Vue3實(shí)現(xiàn)滾動(dòng)條自動(dòng)滾動(dòng)到底部
- vue和uniapp頁(yè)面實(shí)現(xiàn)自動(dòng)滾動(dòng)到最底部
- vue實(shí)現(xiàn)滾動(dòng)底部加載下一頁(yè)指令的示例代碼
- vue滾動(dòng)條滾動(dòng)到頂部或者底部的方法
- vue 解決mintui彈窗彈起來(lái),底部頁(yè)面滾動(dòng)bug問(wèn)題
- vue scroll滾動(dòng)判斷的實(shí)現(xiàn)(是否滾動(dòng)到底部、滾動(dòng)方向、滾動(dòng)節(jié)流、獲取滾動(dòng)區(qū)域dom元素)
- vue實(shí)現(xiàn)頁(yè)面滾動(dòng)到底部刷新
相關(guān)文章
vue最強(qiáng)table vxe-table 虛擬滾動(dòng)列表 前端導(dǎo)出問(wèn)題分析
最近遇到個(gè)問(wèn)題,后臺(tái)一次性返回2萬(wàn)條列表數(shù)據(jù)并且需求要求所有數(shù)據(jù)必須全部展示,不能做假分頁(yè),怎么操作呢,下面通過(guò)本文介紹下vue最強(qiáng)table vxe-table 虛擬滾動(dòng)列表 前端導(dǎo)出問(wèn)題,感興趣的朋友一起看看吧2023-10-10
vue使用JSEncrypt對(duì)密碼本地存儲(chǔ)時(shí)加解密的實(shí)現(xiàn)
本文主要介紹了vue使用JSEncrypt對(duì)密碼本地存儲(chǔ)時(shí)加解密,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07
組件中多個(gè)el-upload存在導(dǎo)致上傳圖片失效的問(wèn)題及解決
這篇文章主要介紹了組件中多個(gè)el-upload存在導(dǎo)致上傳圖片失效的問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03
vue中解決chrome瀏覽器自動(dòng)播放音頻和MP3語(yǔ)音打包到線(xiàn)上的實(shí)現(xiàn)方法
這篇文章主要介紹了vue中解決chrome瀏覽器自動(dòng)播放音頻和MP3語(yǔ)音打包到線(xiàn)上的實(shí)現(xiàn)方法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10
vue使用高德地圖實(shí)現(xiàn)實(shí)時(shí)定位天氣預(yù)報(bào)功能
這篇文章主要介紹了vue使用高德地圖實(shí)現(xiàn)實(shí)時(shí)天氣預(yù)報(bào)功能,根據(jù)定位功能,使用高德地圖實(shí)現(xiàn)定位當(dāng)前城市的天氣預(yù)報(bào)功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-05-05
vue如何基于el-table實(shí)現(xiàn)多頁(yè)多選及翻頁(yè)回顯過(guò)程
在最近的一個(gè)項(xiàng)目中我需要實(shí)現(xiàn)表格的翻頁(yè),并且還要實(shí)現(xiàn)全選、多選功能,下面這篇文章主要給大家介紹了關(guān)于vue如何基于el-table實(shí)現(xiàn)多頁(yè)多選及翻頁(yè)回顯過(guò)程的相關(guān)資料,需要的朋友可以參考下2022-12-12
vue實(shí)現(xiàn)折疊展開(kāi)收縮動(dòng)畫(huà)效果
這篇文章主要介紹了vue實(shí)現(xiàn)折疊展開(kāi)收縮動(dòng)畫(huà),通過(guò)scrollHeight實(shí)現(xiàn),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧2023-11-11
vue 中常用操作數(shù)組的方法(forEach()和reduce())
文章介紹了JavaScript中常用的操作數(shù)組方法,包括forEach()和reduce(),forEach()用于遍歷數(shù)組并對(duì)每個(gè)元素執(zhí)行操作,而reduce()則用于遍歷數(shù)組并進(jìn)行累加等迭代操作,感興趣的朋友一起看看吧2025-03-03
VUE側(cè)邊導(dǎo)航欄實(shí)現(xiàn)篩選過(guò)濾的示例代碼
本文主要介紹了VUE側(cè)邊導(dǎo)航欄實(shí)現(xiàn)篩選過(guò)濾的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-05-05

