微信小程序之七:跑马灯效果

实现跑马灯效果图
图片.png
---wxml文件---
<!--跑马灯中的文字信息字段:gundong_text-->
<view wx:if='{{gundong_text}}' class="marquee_container" style="--marqueeWidth--:-12em">
  <view class='marquee_text'>
    <view class='hengxianggundong'>
      <image class='gundong_image' mode='aspectFit' src='../../image/laba.png'></image>
      <view class='triangle-left'></view>
      <view class="gundong_textView weui-zimFont9">{{gundong_text}}</view>
    </view>
  </view>
</view>
---wxss文件---
/* 跑马灯样式 */
@keyframes around {
  from {
    margin-left: 100%;
  }
  to {
    /* var接受传入的变量 */
    margin-left: var(--marqueeWidth--);
  }
}
.marquee_container {
  position: absolute;
  top: 120rpx;
  width: 100%;
  height: 60rpx;
  line-height: 60rpx;
  z-index: 1200;
}
.marquee_container:hover {
  /* 不起作用 */
  animation-play-state: paused;
}
.marquee_text {
  display: inline-block;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  white-space: nowrap;
  animation-name: around;
  animation-duration: 10s; /*过渡时间*/
  animation-iteration-count: infinite;
  animation-timing-function: linear;
}
.hengxianggundong {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
}
.gundong_image {
  background-color: rgba(0, 0, 0, 0.6);
  width: 50rpx;
  height: 50rpx;
  border-radius: 50%;
  margin-right: 20rpx;
}
.triangle-left {
  width: 0;
  height: 0;
  border-right: 10rpx solid rgba(0, 0, 0, 0.8);
  border-bottom: 10rpx solid rgba(0, 0, 0, 0);
  border-top: 10rpx solid rgba(0, 0, 0, 0);
}
.gundong_textView {
  background-color: rgba(0, 0, 0, 0.8);
  color: white;
  padding-left: 20rpx;
  padding-right: 20rpx;
  border-radius: 10rpx;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容