微信小程序实现跑马灯效果(完整代码)

在微信小程序 里实现跑马灯效果,类似滚动字幕或者滚动广告之类的,使用简单的CSS样式控制,没用到JS,效果如下图:

Wxml代码:



    一个人活着就是为了让更多的人更好的活着!

Wxss代码:

/*首页跑马灯效果*/
@keyframes around {
  from {
   margin-left: 100%;
  }
  to {
   /* var接受传入的变量 */
   margin-left: var(--marqueeWidth--);
  }
 }
 
.marquee_container{
  background-color: #fe4655;
  height: 50rpx;
  line-height: 44rpx;
  position: relative;
  width: 100%;
  margin-top:0rpx;
}
.marquee_container:hover{
  /* 不起作用 */
  animation-play-state: paused;
}
.marquee_text{
  color:#fff;
  font-size: 28rpx;
  display: inline-block;
  white-space: nowrap;
  animation-name: around;
  animation-duration: 10s;  /*过渡时间*/
  animation-iteration-count: infinite;
  animation-timing-function:linear;
}
/*首页跑马灯效果*/

参考小程序: 

微信小程序实现跑马灯效果(完整代码)_第1张图片

 

你可能感兴趣的:(小程序)