色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

vue scroll滾動判斷的實現(是否滾動到底部、滾動方向、滾動節流、獲取滾動區域dom元素)

瀏覽:45日期:2023-01-13 16:11:47

1、是否滾動到底部

isScrollBottom() { // 是否滾動到了底部 this.box = this.$refs.chatListWrapper var clientHeight = this.box.clientHeight var scrollTop = this.box.scrollTop var scrollHeight = this.box.scrollHeight if (scrollTop + clientHeight == scrollHeight) { this.$store.dispatch(’setBottomBtn’, false, { root: true }) // 隱藏直達最新消息按鈕 this.isBottom = true this.isTop = false } else { this.$store.dispatch(’setBottomBtn’, true, { root: true }) // 顯示直達最新消息按鈕 this.isTop = false this.isBottom = false if (scrollTop == 0) { this.isTop = true } } },

2、scroll滾動方向判斷

getDirection() { // scroll滾動方向~~~~ this.box = this.$refs.chatListWrapper var scrollTop = this.box.scrollTop var scroll = scrollTop - this.initTop this.initTop = scrollTop let dir = ’down’ if (scroll < 0) { dir = ’up’ } else { dir = ’down’ } return dir },

3、滾動節流

1)、在滾動的dom上綁定scroll事件,監聽滾動

vue scroll滾動判斷的實現(是否滾動到底部、滾動方向、滾動節流、獲取滾動區域dom元素)

2)、data中定義:fnScroll: () => {}, 初始值3)、mounted中給fnScroll函數賦值,_.throttle實現滾動節流

this.fnScroll = _.throttle(() => {}, 500)

4、獲取滾動可視區域內dom:

實現注意:判斷當前元素是否在可視區域內,若在則存到isSeeDomArr中,然后循環isSeeDomArr數組,拿到當前可視區域內的最后一個dom,再去判斷是否更新對應的咨詢軌跡。不要滾動時就去更新,這樣會造成不停請求更新,最后一次請求可能無效,造成數據的錯亂

sendRead() { const chatLi = document .getElementById(’chat_list_wrapper’) .getElementsByTagName(’li’) var container = this.$refs.chatListWrapper var swHeight = container.clientHeight const scrollTop = container.scrollTop const aa = swHeight + scrollTop let isSeeDomArr = [] for (let j = 0; j < chatLi.length; j++) { if (scrollTop < chatLi[j].offsetTop && chatLi[j].offsetTop < aa) { isSeeDomArr.push(chatLi[j]) //將可視區域內所有dom存儲到isSeeDomArr } } if (isSeeDomArr.length) { // 非 ceo接診臺更新消息的已讀狀態 if (this.$route.path.indexOf(’diagnose/ceo’) === -1) { for (let m = 0; m < isSeeDomArr.length; m++) { const isSelfSend = isSeeDomArr[m].getAttribute(’isSelfSend’) const msgStatus = isSeeDomArr[m].getAttribute(’msgStatus’) const msgType = isSeeDomArr[m].getAttribute(’msgType’) if (!isSelfSend && !msgStatus && msgType !== ’notice’) { const _id = isSeeDomArr[m].getAttribute(’id’) this.sendReadApi(_id) } } } // 更新聊天對應的咨詢軌跡 this.setCurrentFdAsk( isSeeDomArr[isSeeDomArr.length - 1].getAttribute(’fdAsk’) ) } },

the end:滾動加載這些判斷前前后后改了好多次,這次終于感覺邏輯比較清晰了,也算對自己有個交代。。。

到此這篇關于vue scroll滾動判斷的實現(是否滾動到底部、滾動方向、滾動節流、獲取滾動區域dom元素)的文章就介紹到這了,更多相關vue scroll滾動判斷內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Vue
相關文章:
主站蜘蛛池模板: 久久成人免费观看全部免费 | 免费毛片全部不收费的 | 国产精品理论片在线观看 | 久久青草国产手机看片福利盒子 | 久久久久久免费一区二区三区 | 久久99国产精一区二区三区 | 欧美一级免费 | 99热久久精品国产 | 欧美三级不卡在线观看视频 | 美女黄色毛片免费看 | 国内一区二区 | 免费看一级欧美毛片视频 | 亚洲综合一区二区三区 | fc2ppv在线播放| 国产成人精品免费视频 | 久久欧美精品欧美久久欧美 | hdxxx色视频 hd欧美xxx欧美极品hd | 国产一级视频在线观看 | 成人网视频在线观看免费 | 99精彩视频| 成人亚洲天堂 | 欧美特黄aaaaaaaa大片 | 久久免费精品国产72精品剧情 | 毛片在线视频 | 国产精品亚洲一区二区在线观看 | 玖草在线视频 | 欧美一级特黄做 | 毛片免费大全 | 欧洲一级视频 | 一级一级 a爱片免费视频 | 久久毛片视频 | 日韩国产成人资源精品视频 | 一区二区三区四区免费视频 | 国产高清视频在线播放 | 国产91丝袜美腿在线观看 | 一区二区影视 | 91久久综合 | 欧美一级片手机在线观看 | 99国产精品视频久久久久 | 香港经典a毛片免费观看爽爽影院 | 欧美精品不卡 |