vue工程化:返回顶部和底部的动画效果
.
<template>
<div>
<div class="scroll" :class="{show:isActive}">
<div id="toTop" @click="toTop(step)"><</div>
<div id="toBottom" @click="toBottom(step)">></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工程化:返回顶部和底部的动画效果的更多相关文章
- jquery返回顶部和底部插件和解决ie6下fixed插件
(function($){ //返回顶部和底部插件 $.fn.extend({ goTopBootom:function (options){ //默认参数 var defaults = { &quo ...
- jQuery类级别插件--返回顶部,底部,去到任何部位
先引入js:<script type="text/javascript" src="jquery.js" ></script><s ...
- ListView(1)几个重要属性,关闭滚动到顶部,底部的动画,item之间的分割线,背景等
见表: android:stackFromBottom="true" 设置该属性之后你做好的列表就会显示你列表的最下面,值为true和false android:transcrip ...
- Vue 用第三方的库去实现动画效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vue中使用transition和animate.css动画效果
一.单个动画中,使用div中引用animate动画 1.下载依赖 npm install animate.css –save 2.main.js中全局引用 import animate from 'a ...
- css 简单 返回顶部 代码及注释说明
1. 最简单的静态返回顶部,点击直接跳转页面顶部,常见于固定放置在页面底部返回顶部功能 方法一:用命名锚点击返回到顶部预设的id为top的元素 html代码 <a href="#top ...
- Web前端 页面功能——点击按钮返回顶部的实现方法
1. 最简单的静态返回顶部,点击直接跳转页面顶部,常见于固定放置在页面底部返回顶部功能 方法一:用命名锚点击返回到顶部预设的id为top的元素 html代码 <a href="#top ...
- 【Android】Listview返回顶部,快速返回顶部的功能实现,详解代码。
作者:程序员小冰,GitHub主页:https://github.com/QQ986945193 新浪微博:http://weibo.com/mcxiaobing 首先给大家看一下我们今天这个最终实现 ...
- 【Android】Scrollview返回顶部,快速返回顶部的功能实现,详解代码。
作者:程序员小冰,GitHub主页:https://github.com/QQ986945193 新浪微博:http://weibo.com/mcxiaobing 首先给大家看一下我们今天这个最终实现 ...
随机推荐
- codeforces 686C C. Robbers' watch(dfs)
题目链接: C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 创建oracle数据库job服务
创建oracle数据库job服务:PlSqlDev操作job https://www.baidu.com/link?url=5vXhw0IqjvWEAgGSIYsSEVPvJb6njGkJ-_P_VF ...
- c++爬虫子
Larbin是一个用C++开发的开源网络爬虫,有一定的定制选项和较高的网页抓取速度. 下图表示了一般爬虫抓取网页的基本过程. 抓取以/Larbin.conf中的startUrl做为种子URLs开始. ...
- Math对象常用方法(取整细节)
Math 对象 Math 对象用于执行数学任务. 1.常用属性: 1.E :返回算术常量e,即自然对数的底数(约2.718) 2.PI :返回圆周率,约3.14159 2.常用方法 Math.方 ...
- Linux 常用命令十四 killall和pkill
用killall杀死所有同名的进程. wang@wang:~/workpalce/git$ ps -aux | grep vim wang pts/ S+ : : vim a wang pts/ S+ ...
- POJ2486 Apple Tree 【树上背包】
一句话题意:一棵树,一共n个点,每个点上有一个权值,求从1出发,走k步,最多能遍历到的权值.可以往回走. 第一(二)道树上背包题,先是看了dalao的题解,改了一点就过样例了.然而....TLE??? ...
- Sign on Fence CodeForces - 484E
http://codeforces.com/problemset/problem/484/E 题意: 给定一个长度为n的数列,有m次询问,询问形如l r k 要你在区间[l,r]内选一个长度为k的区间 ...
- JEECMSv9.3在金蝶Apusic中间件中无法找到首页的问题处理
在金蝶中间件中启动JEECMS,访问首页显示"页面找不到"信息.而访问后台及其他页面均可正常访问. 经代码查找,发现前台页面的所有地址是通过"com.jeecms.cms ...
- 前台js获得json数据
$.ajax({ type:"post", url:"testAction.action", data:{ classId:classId }, success ...
- ECMAScript6之箭头函数
2015年6月17日,ECMAScript 6发布正式版本,即ECMAScript 2015. 函数作为js语言中的一等公民.自然Es6中推出的箭头函数(=>)也是备受瞩目的.那我们接下来看下传 ...