vue中的回到顶部
<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>
注意图片需要自行进行引入
vue中的回到顶部的更多相关文章
- AspnetPager放在UpdatePanel中,回到顶部。
最近在做一个项目时,使用了AspNetPager分页控件进行分页,为了防止点击下一页时搜索条件消失掉,使用了UpdatePanel来进行局部刷新. 由此引发了一个问题,即点击某一页时,页面没有返回到顶 ...
- Vue+elementUI 创建“回到顶部”组件
1.创建"回到顶部"组件 1 <template> 2 <transition name="el-fade-in"> 3 <div ...
- vue系列---理解Vue中的computed,watch,methods的区别及源码实现(六)
_ 阅读目录 一. 理解Vue中的computed用法 二:computed 和 methods的区别? 三:Vue中的watch的用法 四:computed的基本原理及源码实现 回到顶部 一. 理解 ...
- 【JavaScript Demo】回到顶部功能实现
随着网站的不断发展,需要展示的内容也越来越丰富,这导致网页上能展示的内容越来越多.当内容堆积影响了用户体验,就需考虑如何提升用户体验.在这一系列的改动中,“回到顶部”的功能成为了一个经典. 1.页面布 ...
- js实现回到顶部功能
js实现回到顶部功能 一.总结 一句话总结: 可以通过js或者jquery可以很快的控制页面的属性,比如高度等等 //设置当前视口的顶端数值 var setScrollTop = function(t ...
- vue中回到顶部
1. 回到顶部,使用 scrollIntoView 方法: Element.scrollIntoView方法滚动当前元素,进入浏览器的可见区域 该方法可以接受一个布尔值作为参数.如果为true,表示元 ...
- vue 中<vue-scroll >滚动条回到顶部
今天项目碰到一个<vue-scroll >滚动条要回到顶部的需求,查询了好久终于解决了,这里记录一下: 其实就是scrollIntoView()方法的使用(官方文档): 需要注意的是要求页 ...
- vue 回到顶部的小问题
今天在用vue项目中,实现回到顶部功能的时候,我写了一个backTop组件,接下来需要通过监听window.scroll事件来控制这个组件显示隐藏 因为可能会有其他的组件会用到这样的逻辑,所以将此功能 ...
- vue回到顶部组件
html <template> <a href="javascript:;" class="toTop" @click="backT ...
随机推荐
- 【巨杉数据库SequoiaDB】巨杉Tech | 四步走,快速诊断数据库集群状态
1.背景 SequoiaDB 巨杉数据库是一款金融级分布式数据库,包括了分布式 NewSQL.分布式文件系统与对象存储.与高性能 NoSQL 三种存储模式,分别对应分布式在线交易.非结构化数据和内容管 ...
- Codeforce 567A - Lineland Mail
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its ...
- ASPxGridView 排序、分页、加载数据必需的三个函数
protected void ASPxGridViewPoint_OnCustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs ...
- C语言-const再理解(转)
有时候我们希望定义这样一种变量,它的值不能被改变,在整个作用域中都保持固定.例如,用一个变量来表示班级的最大人数,或者表示缓冲区的大小.为了满足这一要求,可以使用const关键字对变量加以限定: co ...
- vs code使用指南
https://blog.csdn.net/weixin_45601379/article/details/100550421
- C++-POJ2955-Brackets[DP]
题意就是,找出最长合法子括号序列 容易想到设f[l][r]为l~r的最长合法子括号序列的长度 然后从短的状态往长的状态枚举,不断更新答案就可以了 //#include<bits/stdc++.h ...
- Codeforces Round #601 (Div. 2) E1 Send Boxes to Alice (Easy Version)
#include <bits/stdc++.h> using namespace std; typedef long long ll; ; int a[N]; int n; bool pr ...
- go语言 内置的椭圆数字签名及其验证算法
package main import ( "crypto/ecdsa" "crypto/elliptic" "crypto/rand" & ...
- Weather
Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such nat ...
- http接口性能测试工具
一. http_load 程序非常小,解压后也不到100K.http_load以并行复用的方式运行,用以测试web服务器的吞吐量与负载. 但是它不同于大多数压力测试工具,它可以以一个单一的进程运行,一 ...