<template>
<div class="main">
<div class="content">灰色部分是内容部分</div>
<div class="red">红色部分是内容部分</div>
<div class="scollTop" id="imgscoll" v-show="isShowimg === true">
<img src="@/assets/dingbu@3x.png" alt @click="goTop">
</div>
</div>
</template>
<script>
export default {
data(){
return{
isShowimg: false,
}
},
mounted(){
window.addEventListener('scroll', this.handleScroll)
},
destroyed() {
document.removeEventListener('scroll', this.handleScroll)
document.body.scrollTop = document.documentElement.scrollTop =
},
methods:{
goTop() {
// 回到顶部
document.body.scrollTop = document.documentElement.scrollTop =
this.isShowimg = false
},
handleScroll(e) {
// 滚动操作监听
let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
// console.log(scrollTop)
let offsetTop =
try {
offsetTop = document.querySelector('.main').offsetTop
} catch (e) {
offsetTop =
}
if (scrollTop > offsetTop) {
// this.searchBarFixed = true
// this.scrollStatus = {
// display: 'block',
// background: '#fff',
// h: this.statusBarHeight.h
// }
if (scrollTop > ) {
this.isShowimg = true
} else {
this.isShowimg = false
}
} else {
// this.searchBarFixed = false
this.isShowimg = false
// this.scrollStatus = {
// display: 'none',
// background: 'transparent',
// h: 0
// }
}
}
}
}
</script>
<style>
*{
margin:;padding:;
}
.main{
width: %;
}
.content{
width: %;
height:60rem;
background: #eee;
}
.red{
height:30rem;
background: #f00;
}
.scollTop {
position: fixed;
bottom: 15rem;
right: 3rem;
}
.scollTop img{
width: 5rem;
height: 5rem;
}
</style>

注意图片需要自行进行引入

最新文章

  1. Notepad++正则表达式语法
  2. JavaScript Patterns 6.4 Prototypal Inheritance
  3. python数据结构之二叉树遍历的实现
  4. 夺命雷公狗jquery---4内容选择器
  5. weblogic部署ssh2应用出现异常
  6. ZK framework on Java
  7. UVA 10765 Doves and bombs(双连通分量)
  8. 关于wxpython多线程研究包括(import Publisher错误研究)
  9. [asp.net core 源码分析] 01 - Session
  10. 输入input
  11. 随机数Random
  12. linux使用代理进行apt安装 以 nord 为例
  13. Visual Studio 2017 常用快捷键
  14. javascript数据类型的判断
  15. win10屏幕变灰怎么解决?
  16. Python生成器表达式
  17. SpringBoot配置文件的加载位置
  18. 云中树莓派(3):通过 AWS IoT 控制树莓派上的 Led
  19. ABP框架使用Swagger
  20. 在Java的反射中,Class.forName和ClassLoader的区别

热门文章

  1. 洛谷P1308 统计单词数
  2. layedit不可编辑,按钮不能使用
  3. C#关于文件的创建
  4. Eclipse设置代码模板
  5. java多线程CountDownLatch
  6. 番外:Oracle 中关于 Control File 的备份说明
  7. [SUCTF 2019]EasySQL(堆叠注入配合sql_mode)
  8. Windows系统对拍程序
  9. 巨杉Tech | SequoiaDB虚机镜像正式上线
  10. js json -&gt; &lt;-object