css3实现简单动画效果及以小程序为例

效果

点击按钮三角形按照一个三角形的路线移动


css动画.gif

实现思路

主要通过translate这个属性控制对应的x轴y轴的移动zuo biao

实现过程

wxml

<view class="container">
  <view class='triangle {{active?"active":""}}'></view>
  <button class='actionbotton' bindtap='action'>点击开始动画</button>
</view>

css

.container {
  position: relative;
}
//三角形
.triangle {
  width: 0rpx;
  height: 0rpx;
  position: absolute;
  border-left: 50rpx solid transparent;
  border-top: 50rpx solid transparent;
  border-right: 50rpx solid transparent;
  border-bottom: 50rpx solid red;
  margin-top: 300rpx;
}

.actionbotton {
  position: absolute;
  margin-top: 450rpx;
}
//动画定义
.active {
  animation-name: test;//名称
  animation-duration: 3s;//时间
  animation-timing-function: linear;//方式
  animation-iteration-count: 5;//次数
}

@keyframes test {
  0% {
    transform: translate(0rpx, 0rpx);
  }

  20% {
    transform: translate(-300rpx, -300rpx);
  }

  60% {
    transform: translate(300rpx, -300rpx);
  }

  100% {
    transform: translate(0rpx, 0rpx);
  }
}

js

//点击方法
action:function(){
    this.setData({
      active: !this.data.active
    })
  }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 刚要想起你,心就一揪一揪的疼啊。我们在一个软件上相识,那是个看脸的软件,和我当时浮躁的心情简直太搭了 你像那些朋友...
    花慕男阅读 1,566评论 0 0
  • 前两天有一篇文章上了简书封面,号称要开挂的人生,2018年要实现不止100个目标。这篇长文获得几百个赞和几百句的留...
    胡誠阅读 5,699评论 1 11
  • 天使班班长 1201 李夏莲 20180109(9/100) 厦 晴,9-12度 【以梦为马,不负昭华 】 今日我...
    阿白1阅读 606评论 0 0
  • 【自助者天助】 凭借着一股韧劲与自强不息的精神,刘备成功考入长江国际大学,然而,当收到这个通知时,刘备母子悲喜交加...
    褐玉杂货铺阅读 3,709评论 0 2