微信小程序无缝衔接弹幕效果纯CSS

效果图

主要运用蒙层、动画延迟

.wxml

复制代码
<view wx:for="{{detail}}" wx:key="{{index}}" class="container" style="--s:{{item.s}}s" >
  <view wx:for="{{2}}" wx:key="{{index}}" class="container-item">
    <text>HTML</text>
    <text>CSS</text>
    <text>JAVASCRIPT</text>
    <text>PHP</text>
    <text>JAVA</text>
    <text>VUE</text>
    <text>REACT</text>
  </view>
</view>

.js

复制代码
Page({
  data: {
    detail:[{s:10},{s:14},{s:4},{s:18},{s:6}],
  },
})

.wxss

复制代码
page{
  padding-top: 100rpx;
  background: #000;
}
.container{
  position: relative;
  display: flex;
  width:100%;
  overflow: hidden;
  -webkit-mask-box-image: linear-gradient(90deg,transparent,#fff,#fff,transparent);
  margin: 30rpx 0;
}
.container-item{
  white-space: nowrap;
}
.container-item text{
  display: inline-flex;
  margin: 20rpx;
  padding: 10rpx 20rpx;
  color: #fff;
  letter-spacing: 4rpx;
  background: #333;
  border-radius: 10rpx;
}
.container .container-item:nth-child(1){
  animation: animation var(--s) linear infinite;
}
.container .container-item:nth-child(2){
  animation: animation2 var(--s) linear infinite;
  animation-delay: calc(var(--s) / 2);
}
@keyframes animation {
  from{
    transform: translate(100%);
  }
  to{
    transform: translate(-100%);
  }
}
@keyframes animation2 {
  from{
    transform: translate(0);
  }
  to{
    transform: translate(-200%);
  }
}

遇到问题可以看我主页加我Q,很少看博客,对你有帮助别忘记点赞收藏。

相关推荐
小小前端_我自坚强38 分钟前
UniApp 微信小程序开发使用心得
面试·微信小程序·代码规范
软件技术NINI1 小时前
html css js网页制作成品——化妆品html+css+js (7页)附源码
javascript·css·html
前端Hardy3 小时前
HTML&CSS:一眼心动的 SVG 时钟
前端·javascript·css
TTGGGFF3 小时前
Streamlit:CSS——从基础到实战美化应用
前端·css
Hilaku5 小时前
重新思考CSS Reset:normalize.css vs reset.css vs remedy.css,在2025年该如何选?
前端·css·代码规范
右子5 小时前
微信小程序开发“闭坑”指南
前端·javascript·微信小程序
Darenm1116 小时前
深入理解CSS BFC:块级格式化上下文
前端·css
小白64026 小时前
前端梳理体系从常问问题去完善-框架篇(react生态)
前端·css·html·reactjs
吃饺子不吃馅7 小时前
大家都在找的手绘/素描风格图编辑器它它它来了
前端·javascript·css
Zhencode7 小时前
CSS变量的应用
前端·css