15621857753

微信小程序实现跑马灯文字滚动效果实例

来源:齐鲁建站 栏目:开发教程 阅读: 日期:2021-01-23

本文主要介绍了微信小程序实现跑马灯文字滚动效果实例,给出了实例代码,放到自己的模板里面直接使用就可以,推荐给有此需要的朋友,值得参考。

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

小程序,小程序跑马灯

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

Wxml代码:

<!--跑马灯 Linyufan.com-->
<view class="marquee_container" style="--marqueeWidth--:-12em">
<view class="marquee_text">一个人活着就是为了让更多的人更好的活着!</view>
</view>
<!--跑马灯-->

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;
}
/*首页跑马灯效果*/

展开