.

<template>
<div>
<div class="scroll" :class="{show:isActive}">
<div id="toTop" @click="toTop(step)">&lt;</div>
<div id="toBottom" @click="toBottom(step)">&gt;</div>
</div>
</div>
</template>
<script>
export default{
props:{
step:{ //此数据是控制动画快慢的
type:Number,
default:
}
},
data(){
return {
isActive:false,
}
},
methods:{
toTop(i){
//参数i表示间隔的幅度大小,以此来控制速度
document.documentElement.scrollTop-=i;
if (document.documentElement.scrollTop>) {
var c=setTimeout(()=>this.toTop(i),);
}else {
clearTimeout(c);
}
},
toBottom(i){
var clientHeight=document.documentElement.clientHeight||document.body.clientHeight;
var scrollHeight=document.documentElement.scrollHeight;
var height=scrollHeight-clientHeight; //超出窗口上界的值就是底部的scrolTop的值
document.documentElement.scrollTop+=i;
if (document.documentElement.scrollTop<height) {
var c=setTimeout(()=>this.toBottom(i),);
}else {
clearTimeout(c);
}
}
},
created(){
var vm=this;
window.onscroll=function(){
if (document.documentElement.scrollTop>) {
vm.isActive=true;
}else {
vm.isActive=false;
}
}
}
}
</script>
<style scoped>
.scroll{
position: fixed;
right: 10px;
bottom: 60px;
width: 45px;
height: 90px;
cursor: pointer;
display: none;
}
.scroll>div{
width: 45px;
height: 45px;
transform: rotate(90deg);
line-height: 45px;
text-align: center;
font-size: 35px;
font-family: "黑体";
background-color: rgba(,,,.);
color: #fff;
}
.scroll>div:hover{
background-color: rgba(,,,.);
}
.show{
display: block;
}
</style>

vue工程化:返回顶部和底部的动画效果的更多相关文章

  1. jquery返回顶部和底部插件和解决ie6下fixed插件

    (function($){ //返回顶部和底部插件 $.fn.extend({ goTopBootom:function (options){ //默认参数 var defaults = { &quo ...

  2. jQuery类级别插件--返回顶部,底部,去到任何部位

    先引入js:<script type="text/javascript" src="jquery.js" ></script><s ...

  3. ListView(1)几个重要属性,关闭滚动到顶部,底部的动画,item之间的分割线,背景等

    见表: android:stackFromBottom="true" 设置该属性之后你做好的列表就会显示你列表的最下面,值为true和false android:transcrip ...

  4. Vue 用第三方的库去实现动画效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. vue中使用transition和animate.css动画效果

    一.单个动画中,使用div中引用animate动画 1.下载依赖 npm install animate.css –save 2.main.js中全局引用 import animate from 'a ...

  6. css 简单 返回顶部 代码及注释说明

    1. 最简单的静态返回顶部,点击直接跳转页面顶部,常见于固定放置在页面底部返回顶部功能 方法一:用命名锚点击返回到顶部预设的id为top的元素 html代码 <a href="#top ...

  7. Web前端 页面功能——点击按钮返回顶部的实现方法

    1. 最简单的静态返回顶部,点击直接跳转页面顶部,常见于固定放置在页面底部返回顶部功能 方法一:用命名锚点击返回到顶部预设的id为top的元素 html代码 <a href="#top ...

  8. 【Android】Listview返回顶部,快速返回顶部的功能实现,详解代码。

    作者:程序员小冰,GitHub主页:https://github.com/QQ986945193 新浪微博:http://weibo.com/mcxiaobing 首先给大家看一下我们今天这个最终实现 ...

  9. 【Android】Scrollview返回顶部,快速返回顶部的功能实现,详解代码。

    作者:程序员小冰,GitHub主页:https://github.com/QQ986945193 新浪微博:http://weibo.com/mcxiaobing 首先给大家看一下我们今天这个最终实现 ...

随机推荐

  1. svn问题:在eclipse里面使用SVN,怎么实现版本回滚呢?

    共有4个答案 我要回答» JustForFly 回答于 2012-04-27 10:20 举报   想回到SVN服务器端的最新版本就使用 team->还原.. 想回到SVN服务器端的其它版本使用 ...

  2. 输出两个MAC地址之间的地址

    /******************************************************************************* * 输出两个MAC地址之间的地址 * ...

  3. bzoj1566 [NOI2009]管道取珠——DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1566 一眼看上去很懵... 但是答案可以转化成有两个人在同时取珠子,他们取出来一样的方案数: ...

  4. bzoj2038 小Z的袜子(hose)——莫队算法

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2038 就是莫队算法: 先写了个分块,惨WA: #include<iostream> ...

  5. [转]响应式web设计之CSS3 Media Queries

    开始研究响应式web设计,CSS3 Media Queries是入门. Media Queries,其作用就是允许添加表达式用以确定媒体的环境情况,以此来应用不同的样式表.换句话说,其允许我们在不改变 ...

  6. html title属性

    <table class="table table-hover table-striped"> @foreach (var article in Model) { &l ...

  7. 阿里DNS 223.5.5.5 223.6.6.6 (转载)

    转自:http://it.oyksoft.com/post/6780/ 阿里DNS:   223.5.5.5       223.6.6.6 为何用它? 一.选择阿里DNS让你购物更爽,如果是淘宝狂人 ...

  8. bzoj 1922: [Sdoi2010]大陆争霸【dijskstra】

    d[u]为u被几个节点保护,d1[u]为最早到u的时间,d2[u]为u的最早可进入时间(保护点都被打下来了的时候),然后最终最早进入时间就是max(d1[u],d2[u]),把这个作为权值放进小根堆, ...

  9. jacoco 的使用及与jenkins的集成

    1.把jacocoagent.jar的包放入到dockerfile COPY jacocoagent.jar /opt/jacoco/lib/jacocoagent.jar 2.打完镜像,需要启动容器 ...

  10. A - Add More Zero

    Bryce1010模板 #include <bits/stdc++.h> using namespace std; #define LL long long int main() { in ...