当前位置:网站首页>直播平台开发,进入可视区域执行动画、动效、添加样式类名
直播平台开发,进入可视区域执行动画、动效、添加样式类名
2022-06-29 21:58:00 【云豹网络科技】
直播平台开发,进入可视区域执行动画、动效、添加样式类名
添加一个全局自定义指令
import Vue from 'vue'
//注册'v-animate' 当元素出现在可视范围时添加类名触发动效样式
Vue.directive('animate', {
inserted: function (el, binding) {
// 聚焦元素
binding.addClass = () => {
const {
top } = el.getBoundingClientRect()
const h = document.documentElement.clientHeight || document.body.clientHeight
if (top < h) {
if(el.className.indexOf(binding.value) == -1 ){
// 初次还未绑定过,则新增类名(注意:下面单引号中间是一个空格!!!)
el.className = binding.value+' '+el.className
}
if (binding.addClass) {
window.removeEventListener('scroll', binding.addClass)
}
}
}
window.addEventListener('scroll', binding.addClass,true)
binding.addClass()
},
unbind: function (el, binding) {
if (binding.addClass) {
window.removeEventListener('scroll', binding.addClass)
}
}
})
回到html中给需要添加动效的地方添加上 类名
<p class="title" v-animate="'queue-bottom'">我是需要动效的标题</p>
动画效果:
@keyframes bottomMoveTop{
0%{
opacity: 0;
transform: translate3d(0, 50px, 0);
}
100% {
opacity: 1;
transform: none;
}
}
.queue-bottom {
animation: bottomMoveTop .6s cubic-bezier(.5,1,.89,1);
animation-fill-mode: forwards;
}
以上就是直播平台开发,进入可视区域执行动画、动效、添加样式类名, 更多内容欢迎关注之后的文章
边栏推荐
- Graduation summary of construction practice camp
- A mysql IBD file is too large processing record
- Huawei cloud AOM version 2.0 release
- 状态管理 利用Session限制页面访问 只有通过登录验证SessionLogin.aspx才能访问Session.aspx
- MooseFS的简介、部署及应用
- 如果我在珠海,到哪里开户比较好?究竟网上开户是否安全么?
- Dynamics 365online lookup lookup field multiple selection
- Simple analysis of wieshark packet capturing MySQL protocol
- 软件快速交付真的需要以安全为代价吗?
- Taro2.* applet configuration sharing wechat circle of friends
猜你喜欢

Simple understanding of why to rewrite hashcode and equals methods at the same time
![The inadvertently discovered [tidb cache table] can solve the read / write hotspot problem](/img/96/b1595b9d2b008b353765caa68fdd3c.png)
The inadvertently discovered [tidb cache table] can solve the read / write hotspot problem

ASP using panel to realize simple registration page

Deep learning remote sensing data set

Cout ambiguous problem

科大讯飞 AI 学习机暑期新品发布会 AI + 教育深度结合再创产品新高度

为什么要同时重写hashcode和equals方法之简单理解

Reading notes on how to connect the network - LAN on the server side (4)

The logic behind the three whys encountered in technical communication

Simple analysis of wieshark packet capturing MySQL protocol
随机推荐
Golang operation etcd
5-minute quick start pytest testing framework
状态管理 利用Session限制页面访问 只有通过登录验证SessionLogin.aspx才能访问Session.aspx
Huawei cloud AOM version 2.0 release
Reading notes on how to connect the network - LAN on the server side (4)
Autodesk Revit 2023 software installation package download and installation tutorial
The correct method for Navicat to connect to mysql8.0 (valid for personal testing)
小型图书馆项目总结
Hardware development notes (VIII): basic process of hardware development, making a USB to RS232 module (VII): creating a basic dip component (crystal oscillator) package and associating the principle
CLI tool foundation of ros2 robot f1tenth
Taro2.* applet configuration sharing wechat circle of friends
铝板AS/NZS 1530.1 不燃性材料的阻燃测试
Ce CDC Flink peut - il être utilisé pour la synchronisation incrémentale d'Oracle à MySQL?
DevCloud加持下的青软,让教育“智”上云端
A. Beat The Odds
Graduation summary of construction practice camp
Résumé du projet de petite bibliothèque
Common PostgreSQL data operation notes: time
Matplotlib histogram
How to make good use of data science?