VUE實(shí)現(xiàn)吸底按鈕
本文實(shí)例為大家分享了VUE實(shí)現(xiàn)吸底按鈕的具體代碼,供大家參考,具體內(nèi)容如下
<template> <div id='test'> <ul class='list-box'> <li v-for='(item, key) in 50' :key='key'> {{ item }} </li> </ul> <transition name='fade'> <p : v-if='headerFixed'> 吸底按鈕 </p> </transition> </div></template> <script>export default { name: ’test’, data() { return { headerFixed: false, } }, mounted() { window.addEventListener(’scroll’, this.handleScroll) }, destroyed() { window.removeEventListener(’scroll’, this.handleScroll) }, methods: { handleScroll() { const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop this.headerFixed = scrollTop > 50 }, },}</script> <style lang='scss' scoped='scoped'>#test { .list-box { padding-bottom: 50px; } .go { background: pink; text-align: center; line-height: 50px; width: 100%; } .isFixed { position: fixed; bottom: 0; } .fade-enter { opacity: 0; } .fade-enter-active { transition: opacity 0.8s; } .fade-leave-to { opacity: 0; } .fade-leave-active { transition: opacity 0.8s; }}</style>
效果圖:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 使用 kind 和 Docker 啟動(dòng)本地的 Kubernetes環(huán)境2. idea刪除項(xiàng)目的操作方法3. Ajax請(qǐng)求超時(shí)與網(wǎng)絡(luò)異常處理圖文詳解4. HTML <!DOCTYPE> 標(biāo)簽5. 表單中Readonly和Disabled的區(qū)別詳解6. 在layer彈出層中通過(guò)ajax返回html拼接字符串填充數(shù)據(jù)的方法7. XML五則技巧總結(jié)8. js控制臺(tái)報(bào)錯(cuò)Uncaught TypeError: Cannot read properties of undefined (r9. asp循環(huán)語(yǔ)句總結(jié)10. .Net反向代理組件Yarp用法詳解
