前端动画框架GSAP框架随笔
gsap是目前非常流行的前端动画框架,可以非常轻松构造出复杂的动画效果,这里仅对我实际使用中的一些例子进行总结
示例
基础用法
// 声明一个滚动控制器
let ctrl = new ScrollMagic.Controller({
globalSceneOptions:{
offset:-200
}
})
// MORE+
Array.from(document.querySelectorAll(".more")).forEach((el,ix)=>{
let moreLink = new TimelineMax();
moreLink.from(el,{yPercent:300,opacity:0}) // 在timelineMax中 from是指从某种样式过渡到现在的样式
new ScrollMagic.Scene({
triggerElement:document.querySelectorAll("#app div.home")[0].children[ix+3],
triggerHook:0.35,
offset:200
}).setTween(moreLink).addTo(ctrl)
})
// 同时控制两个元素的过渡动画
// 师资简介
init_swiper_teachear(){
const vue = this
class SwiperTeacher{
now = 0
max = vue.swiperTeacher.length-1
imgDom = null;
infosDom = null;
numListDom = null
constructor () {
vue.$nextTick(()=>{this.getDom()})
}
next(){
return new Promise(async (resolve) => {
if(this.now === this.max) vue.goNext('ADVANTAGE');
const imgEnd = gsap.to(this.imgDom[this.imgDom.length - 1 -this.now],{xPercent:-100,ease:'power2.out'})
const infosEnd = gsap.to(this.infosDom[0],{xPercent:(this.now+1) * 100,ease:'power2.out'})
await imgEnd
await infosEnd
this.now+=1
resolve()
})
}
pre(){
return new Promise(async (resolve) => {
if(this.now===0){resolve();return}
this.now-=1
const imgEnd = gsap.to(this.imgDom[this.imgDom.length - 1 - this.now],{xPercent:0,ease:'power2.out'})
const infosEnd = gsap.to(this.infosDom[0],{xPercent:(this.now)*100,ease:'power2.out'})
await imgEnd
await infosEnd
resolve()
})
}
async go(ix){
const needGo = ix-this.now
if(needGo===0) return;
if(needGo<0){
for(let i = 0;i<-needGo;i++){await this.pre()}
}else{
for(let i = 0;i<needGo;i++){await this.next()}
}
}
getDom(){
this.imgDom = document.querySelectorAll('.introductionOfTeachers .sliderContent .imgContent .img')
this.infosDom = document.querySelectorAll('.introductionOfTeachers .sliderContent .infoContent')
this.numListDom = document.querySelectorAll('.introductionOfTeachers .point-teacher .numList')
}
}
let control = new SwiperTeacher()
control = new Proxy(control,{
set (target, p, value) {
if(p==='now'){
control.numListDom.forEach((el,ix)=>{
el.classList.remove('active')
if(ix===value){el.classList.add('active')}
})
}
target[p] = value
return true
}
})
this.$refs['sliderRight-teacher'].addEventListener('click',async ()=>{await control.next()})
this.$refs['sliderLeft-teacher'].addEventListener('click',async ()=>{await control.pre()})
this.$nextTick(()=>{this.$refs['numList-teacher'].forEach((el,ix)=>{el.addEventListener('click',async ()=>{await control.go(ix)})})})
let randomTeacher = new TimelineMax()
randomTeacher.from('div.introductionOfTeachers .sliderContent',{
yPercent:100,
opacity:0,
onStart(){
vue.swiperTeacher = vue.randomArr(vue.raw_teacher_data,5)
control.now = 0
}
})
randomTeacher.from('div.introductionOfTeachers .point-teacher',{
yPercent:100,
opacity:0
})
new ScrollMagic.Scene({triggerElement:'div.introductionOfTeachers',triggerHook:0.35}).setTween(randomTeacher).addTo(ctrl)
}
// 对某个按钮的过渡动画经行处理 通过添加一层元素来经行动画 高阶函数来处理抖动
// 选择院校和新闻大按钮
init_design_button(){
Array.from(document.querySelectorAll('div.selectInstitution .listContent .designButton,div.news .listContent .designButton')).forEach((el,ix)=>{
class onceFunction{
constructor (bg) {
this.bg = bg
this.end = false
}
main(){
this.bg.style.backgroundColor = '#e06730'
this.bg.style.visibility = 'unset'
gsap.from(this.bg,{scaleX:0}).then(()=>{this.end = true})
}
move(){
this.main()
this.move = ()=>{}
}
leave(){
if(this.end){
this.bg.style.visibility = 'hidden'
this.move =()=>{
this.main()
this.move = ()=>{}
}
}
}
}
const o = new onceFunction(el.childNodes[0].childNodes[0])
el.addEventListener('mousemove', ()=>{o.move()})
el.addEventListener('mouseleave',()=>{o.leave()})
if(ix===0||ix===3){
o.move()
}
})
}
前端动画框架GSAP框架随笔的更多相关文章
- 准备.Net转前端开发-WPF界面框架那些事,值得珍藏的8个问题
题外话 不出意外,本片内容应该是最后一篇关于.Net技术的博客,做.Net的伙伴们忽喷忽喷..Net挺好的,微软最近在跨平台方面搞的水深火热,更新也比较频繁,而且博客园的很多大牛也写的有跨平台相关技术 ...
- Yii框架学习笔记(二)将html前端模板整合到框架中
选择Yii 2.0版本框架的7个理由 http://blog.chedushi.com/archives/8988 刚接触Yii谈一下对Yii框架的看法和感受 http://bbs.csdn.net/ ...
- (转) 基于Theano的深度学习(Deep Learning)框架Keras学习随笔-01-FAQ
特别棒的一篇文章,仍不住转一下,留着以后需要时阅读 基于Theano的深度学习(Deep Learning)框架Keras学习随笔-01-FAQ
- 前端开发者使用JS框架的三个等级
目前前端开发者使用JS框架是种很普遍的现象,因为框架可以加快开发速度,同时避免各类浏览器的兼容性问题.不过同样是用框架开发,不同开发者的境界水平还是有一定差距,本文将这些前端开发者分为三个等级. 第一 ...
- Web前端-Vue.js必备框架(五)
Web前端-Vue.js必备框架(五) 页面组件,商品列表组件,详情组件,购物车清单组件,结算页组件,订单详情组件,订单列表组件. vue-router 路由 vuex 组件集中管理 webpack ...
- Web前端-Vue.js必备框架(四)
Web前端-Vue.js必备框架(四) 计算属性: <div id="aaa"> {{ message.split('').reverse().join('') }} ...
- Web前端-Vue.js必备框架(三)
Web前端-Vue.js必备框架(三) vue是一款渐进式javascript框架,由evan you开发.vue成为前端开发的必备之一. vue的好处轻量级,渐进式框架,响应式更新机制. 开发环境, ...
- Web前端-Vue.js必备框架(二)
Web前端-Vue.js必备框架(二) vue调式工具vue-devtools 过滤器:vue.js允许你自定义过滤器,可被用作一些常见的文本格式化. mustache插值和v-bind表达式. vu ...
- Web前端-Vue.js必备框架(一)
Web前端-Vue.js必备框架(一) <!DOCTYPE html> <html lang="en"> <head> <meta cha ...
随机推荐
- OpenSSL编程模型
相关头文件: #include <openssl/ssl.h>#include <openssl/err.h> 客户端程序编写流程: 服务端编写流程: 产生私钥:# opens ...
- 网站搭建-云服务器ECS的使用
1. 查看购买的云服务器实例,重置密码 2. 查找IP进行查看,此时网页时不存在的,开始配置: 3. 登录putty或其他终端,进行网页搭建,先按教程走一遍,然后再做个性化处理: #安装Apache ...
- Redis 的完整安装过程
Windos 版本安装 Redis 官方并不支持 Window 版本,但是微软公司在 Github 上维护了一个 Windows 版本的 Redis 项目,供 Windows 用户下载使用. 下载地址 ...
- 多测师接口测试 --常见的接口面试题目002---高级讲师肖sir
1.postman接口测试,它有一个功能可以设置参数化,你有用过吗 2.你测试过哪些接口 3.有做过接口测试吗?接口测试你们是怎么测的 4.多接口怎么测(postman里面有一个批量处理) 5.g ...
- js、css等文件引入空白问题
路径没错,不管路径怎么改变,js.css等文件就是引入失败.很多时候是因为Spring的过滤器把js.css等资源文件拦截了.default是tomcat配置的一个servlet,"Defa ...
- pytest文档54-Hooks函数terminal打印测试结果(pytest_report_teststatus)
前言 使用命令行执行pytest用例的时候,会在 terminal 终端打印整个用例的测试结果: .代表通过的用例 F代表失败的用例 E代表异常的用例 如果我们不喜欢这种报告结果,可以通过 pytes ...
- 如何轻松使用 C 语言实现一个栈?
什么是数据结构? 数据结构是什么?要了解数据结构,我们要先明白数据和结构,数据就是一些int char 这样的变量,这些就是数据,如果你是一个篮球爱好者,那么你的球鞋就是你的数据,结构就是怎么把这些数 ...
- 震惊!OI居然还考天体运动
看图说话 看这里: 标签: 标签竟然还是模拟,简直活到爆,物理老师狂喜
- abp(net core)+easyui+efcore实现仓储管理系统——出库管理之三(五十一)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统--ABP总体介绍(一) abp(net core)+ ...
- 【Azure Redis 缓存 Azure Cache For Redis】当使用Jedis客户端连接Redis时候,遇见JedisConnectionException: Could not get a resource from the pool / Redis connection lost
问题情形 当在执行Redis一直指令时,有可能会遇见如下几种错误: 1) redis.clients.jedis.exceptions.JedisConnectionException: Could ...