微信小程序封装的几个常用功能

页面中引用


var animate = require('../../utils/animate.js');

show(this,param,time)

显示

*参数1:this;
*参数2 param:定义的动画名param
参数3 time:动画执行时间 。 默认值400ms
wxml中调用方法:animation=’{{param}}’
*使用的元素需要先用hide方法隐藏
<view animation='{{param}}'></view>
onReady:function(){
    let that=this;
    animate.hide(that,that.data.param,1);//使用的元素需要先用hide方法隐藏  
    setTimeout(function(){
        animate.hide(that,that.data.param,500);
    },500)
}

hide(this,param,time)

隐藏

*参数1:this;
*参数2 param:定义的动画名param
参数3 time:动画执行时间 。 默认值400ms
wxml中调用方法:animation=’{{param}}’
<view animation='{{param}}'></view>
onReady:function(){
    let that=this;
    animate.hide(that,'pram',1);//使用的元素需要先用hide方法隐藏  
}

isMove(e,direction,callback)

触摸方向事件

*参数1 e:滑动钩子的e对象;
*参数2 direction:往哪个方向滑动触发(‘left’,‘right’,‘top’,‘bottom’);
参数3:回调
<view bind:touchmove="isMove"></view>
isMove:function(e){
    let that=this;
    animate.isMove(e,'left',()=>{
        //如果向左滑动则触发
    },this)
}

getHeight(id,callback)

获取节点高度

*参数1 id:节点id;
*参数2 callback:回调 返回目标left,right,top,bottom属性;
<view id='ddd'></view>
onReady:function(){
   animate.getHeight('ddd',(res)=>{
       consonle.log(res)
   })
}

getNode(name,arr,callback)

获取节点基本属性

*参数1 name:节点名 ‘#ddd’/’.aaa’;
参数2 arr:目前提供的基本属性有:
backgroundColor,color,fontSize,height,margin,padding,scrollHeight,scrollLeft,scrollTop,scrollWidth,width;如果想获取的属性这里没有可以填写在arr里
*参数3:返回基本属性
<view id='ddd'></view>
onReady:function(){
   animate.getNode('#ddd',['border'],(res)=>{
       consonle.log(res)
   })
}

getWxImg(src,callback)

网络图片本地化

*参数1 src:图片网络路径;
*参数2 callback:回调 返回图片基本信息
onReady:function(){
   animate.getWxImg('https://pic2.zhimg.com/50/v2-88fd57c6464e1a313d5c3337aba07458_hd.jpg',(res)=>{
       consonle.log(res)
   })
}

strSm(str,len)

分割字符串 将字符串分割为字符长度为len的数组

*参数1 str:需要分割的字符串;
参数2 len:在长度大于多少时开始分割 默认:1
onReady:function(){
    let str='adadaadaddad'
    let newStr=animate.strSm(str,5);
    //[adada,adadd,ad]
}

fontEllipsis(str,len,end)

将多余文字显示为省略号

*参数1 str:需要处理的字符串;
参数2 len:在长度大于多少之后为省略号 默认为5
参数3 end:结尾显示内容 默认为‘…’
onReady:function(){
    let str='adadaadaddad'
    let newStr=animate.fontEllipsis(str,5,'???');
    //'adada???'
}

持续更新中。。。。。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值