微信小程序:无需JS,超简单利用CSS3搭建跑马灯

看过有利用JS定时器的,有利用微信小程序动画API的,都比较复杂,须不知CSS3可以简单的设置动画效果咩,还是此方法so easy!

.wxml文件:

<template name='raceLamp'>
  <view class='lamp_container'>
    <view class='lamp_text'>{{lampContent}}</view>
  </view>
</template>

(lampContent是要传入的跑马灯文字内容)

.wxss文件:

.lamp_container {
  background-color: #fe4655;
  position: fixed;
  width: 100%;
  height: 50rpx;
  line-height: 44rpx;
  top: 0;
  left: 0;
  z-index: 10;
}

.lamp_text {
  color: #fff;
  font-size: 28rpx;
  display: inline-block;
  white-space: nowrap;
  animation: horseRunning 15s linear infinite;
}

@keyframes horseRunning {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(-100%);
  }
}

主要就是用了animation属性,以及@keyframes规则,通过改变transform的x轴达到跑马灯左右移动效果。(相关CSS属性介绍可点击查看)

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值