当前位置:网站首页 > Vue.js开发 > 正文

VUE实现吸底

<template> <div id="test"> <ul class="list-box"> <li v-for="(item, key) in 50" :key="key"> { 
  { item }} </li> </ul> <transition name="fade"> <p :class="['go', { isFixed: headerFixed }]" 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>

效果图: 

到此这篇VUE实现吸底的文章就介绍到这了,更多相关内容请继续浏览下面的相关推荐文章,希望大家都能在编程的领域有一番成就!

版权声明


相关文章:

  • 移动端兼容安卓456实现0.5像素边框2024-12-02 21:27:06
  • vue post application/x-www-form-urlencoded传参的解决方案2024-12-02 21:27:06
  • vue安装npm时遇到 npm ERR! syscall rename npm ERR!错误解决办法2024-12-02 21:27:06
  • js事件循环机制-宏任务微任务2024-12-02 21:27:06
  • 对修饰器的实验支持功能在将来的版本中可能更改。在 “tsconfig“ 或 “jsconfig“ 中设置 “experimentalDecorators“ 选项以删除此警告。ts(1219)2024-12-02 21:27:06
  • VUE页面不刷新时调用forceUpdate即可2024-12-02 21:27:06
  • vue mint-ui中swipe高度自适应2024-12-02 21:27:06
  • VUE手写实现移动端el-table组件2024-12-02 21:27:06
  • VUE防止路由重复点击报错2024-12-02 21:27:06
  • vue中父组件传值给子组件,父组件值改变,子组件不能重新渲染2024-12-02 21:27:06
  • 全屏图片