使用Vue添加按鈕點(diǎn)擊實(shí)現(xiàn)返回頂部?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
實(shí)例代碼:
<template> <div class="scrollTop"> <div class="backTop" @click="backTop"> <button v-show="flag_scroll"> 返回頂部 </button> </div> //數(shù)據(jù)源 <div></div> </div> </template> <script> export default { name: 'scrollTop', data() { return { flag_scroll: false, scroll: 0, } }, computed: {}, methods: { //返回頂部事件 backTop() { document.getElementsByClassName('scrollTop')[0].scrollTop = 0 }, //滑動(dòng)超過200時(shí)顯示按鈕 handleScroll() { let scrollTop = document.getElementsByClassName('scrollTop')[0] .scrollTop console.log(scrollTop) if (scrollTop > 200) { this.flag_scroll = true } else { this.flag_scroll = false } }, }, mounted() { window.addEventListener('scroll', this.handleScroll, true) }, created() { }, } </script> <style scoped> .scrollTop{ width: 100%; height: 100vh; overflow-y: scroll; } .backTop { position: fixed; bottom: 50px; z-index: 100; right: 0; background: white; } </style>
網(wǎng)站題目:使用Vue添加按鈕點(diǎn)擊實(shí)現(xiàn)返回頂部-創(chuàng)新互聯(lián)
網(wǎng)站路徑:http://chinadenli.net/article28/deicjp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、云服務(wù)器、App開發(fā)、品牌網(wǎng)站建設(shè)、品牌網(wǎng)站制作、電子商務(wù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容