关于time-gallery的链式封装(可链式调用)

本文介绍了一个使用ES5 prototype链式封装方法实现的动画插件,通过构造不同层级的JSON对象来管理和添加元素,并实现了基本的动画操作。文章还探讨了面向对象的实现方式和技术难点。

插件地址:https://github.com/chenliangwulin/time-gallery
封装语言:es5 prototype链式封装(es6)
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Inheritance_and_the_prototype_chain
//需要面向对象,class的写法吗?prototype的写法吗?

实现方式
https://blog.youkuaiyun.com/owen_william/article/details/51344700

技术难点
层级json的处理:如何向层级相关添加元素,构造完整的json
相关参考文章
https://www.cnblogs.com/xiehaitao/articles/7049913.html
接口预览
function animate(){
var canvas_data="";
this.Container=function(id){
this.canvas_data="{id:"+id+"}";
return this; } //return this
this.Children=function(){
return this;}
this.Bitmap=function(){
return this; }
this.Text=function(){
return this; }
this.Shape=function(){
return this; }
this.Sprite=function(){
return this; }
}
animate.prototype={ //长图类动画原型封装
fromTo:function(){
return this; },
prop:function(){
return this; },
animate:function(){ }
//TweenMax.fromTo(".title", 2, {opacity:0,top:“5%”},{opacity:1,top:“10%”,ease: Bounce.easeOut});
// fromTo:function(".title",2,{},{}){ // 接口参照于tweenmax的接口
// console.log(“i am 1”);
// return this;
// }
}

JS中生成JSON对象的方法
https://www.cnblogs.com/jiangyy/p/3531150.html
先新建一个对象
在这里插入图片描述
变量初始化
在这里插入图片描述
思路分析
本质上是构造对象,json,然后返回json
因为json有多个层级(本例就两个层级),所以设置了ischildren变量
ischildren变量设置好后,需要在contain,bitmap,text,sprite再设相应的值。
在这里插入图片描述
在这里插入图片描述然后在prop方法便可根据对应的值添加prop属性
在这里插入图片描述
注意要点

扩展
vscode+typescript的智能提示
https://segmentfault.com/a/1190000009247663?utm_source=tag-newest

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值