美文网首页
小程序-按住执行动画

小程序-按住执行动画

作者: 没_有_人 | 来源:发表于2018-12-27 10:32 被阅读0次
name.gif

效果图如上图所示:按住执行一段动画,松开的话中断动画。动画执行完以后发送一个请求。
实现思路:点击开始的时候执行动画,并且定时器三秒以后开始发送请求,松开的时候结束动画,并且清除定时器。动画执行的时间是三秒钟,并且停留在最后一帧。

wxml代码

<view class='wrap {{rotate? "aniwrap" : "" }}'>
      <view class='circle {{rotate? "anileft" : "" }}'></view>
        <view class='circle {{rotate? "aniright" : "" }}'></view>
    </view>

wxss代码

.wrap{
  width: 124rpx;
  height: 124rpx;
  position: absolute;
  top:0;
  left: 0;
  clip: rect(0rpx, 124rpx, 124rpx, 62rpx);
}
.circle {
  width: 120rpx;
  height: 120rpx;
  border: 2rpx solid white;
  border-radius: 50%;
  position: absolute;
  top:0;
  left: 0;
  clip: rect(0rpx, 62rpx, 124rpx, 0rpx);
}
.aniwrap{
  animation-duration: 0.01s;
  animation-delay: 1.5s; 
  animation-name: close-wrapper;
  animation-iteration-count: 1;  
    animation-fill-mode: forwards; 
    animation-timing-function:linear; 
}
.anileft{
  animation-duration: 3s;
    animation-name: left-spin;
  animation-iteration-count: 1;  
    animation-fill-mode: forwards; 
    animation-timing-function:linear; 
}
.aniright{
  animation-duration: 1.5s;
    animation-name: right-spin;
  animation-iteration-count: 1;  
    animation-fill-mode: forwards; 
    animation-timing-function:linear; 
}
@keyframes right-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(180deg);
  }
}
@keyframes left-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
@keyframes close-wrapper {
  to {
    clip: rect(auto, auto, auto, auto);
  }
}

js代码

let Time;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    is_use:0,
    rotate:false
  },
  startFn:function(){
    let _this = this;
    this.setData({ rotate: true });
    Time = setTimeout(function(){
      api.Api("Reward/hexiao",{},function(res){
        if(res.data.s){
          _this.setData({is_use:1})
        }else{
          wx.showToast({ title:res.data.m, icon:'none' })
        }
      })
    },3000)
  },
  startEnd:function(){
    clearTimeout(Time);
    this.setData({ rotate: false });
  }
})

相关文章

  • 小程序-按住执行动画

    效果图如上图所示:按住执行一段动画,松开的话中断动画。动画执行完以后发送一个请求。实现思路:点击开始的时候执行动画...

  • 小程序动画创建及动画结束的监听事件

    小程序动画创建 绑定动画数据 设置动画 监听动画事件(开始,结束) 动画执行过程中使用 bindtransitio...

  • mpvue入坑问题

    1.微信小程序的动画只能执行一次,动画执行的是差值: animation.rotate(360).step(...

  • 小程序 动画

    一、过渡、动画、转换间的总结 对应链接手动触发-->改变属性 + transition属性说明=css过渡cs...

  • 小程序动画

    基础:transform属性基础使用[https://www.runoob.com/cssref/css3-pr-...

  • 小程序:动画

    2022-04-08 animation文档[https://www.w3school.com.cn/cssref...

  • 小程序动画

    效果需求 1 .先向上,然后向左,一个插入的效果2 .向上有回弹 实现帧动画 this.animate 1 .缺点...

  • 微信小程序创建动画

    微信小程序创建动画 本文说下微信小程序的动画创建先看效果图 [video(video-ahQoAtNe-15889...

  • 微信小程序学习笔记

    在微信小程序小技巧 1,在微信小程序的开发者工具中按住alt + shift + F 可以格式化代码样式。2,在a...

  • CSS动画|JavaScript动画|小程序动画

    资源推荐:CSS动画的12个原则 Animation Principles for the Web (1)CSS3...

网友评论

      本文标题:小程序-按住执行动画

      本文链接:https://www.haomeiwen.com/subject/cdlklqtx.html