微信小程序里實現跑馬燈效果


在微信小程序 里實現跑馬燈效果,類似滾動字幕或者滾動廣告之類的,使用簡單的CSS樣式控制,沒用到JS

wxml:

<!-- 復制的跑馬燈效果 -->
<view class="marquee_container" style="--marqueeWidth--:-12em">
  <view class="bulletin_box_img2">
    <image src="../../images/icon/bulletin.png" alt=""></image>
  </view>
  <view class="marquee_text">積分商城兌換商品將於每月25日集中發貨,請耐心等待,介意慎拍</view>
</view>

wxss:

/*首頁跑馬燈效果*/
@keyframes around {
  from {
   margin-left: 50%;
  }
  to {
   /* var接受傳入的變量 */
   margin-left: var(--marqueeWidth--);
  }
  }
   
 .marquee_container{
  background-color: #fff;
  height: 80rpx;
  line-height: 80rpx;
  position: relative;
  width: 100%;
  margin-top:0rpx;
 }
 .marquee_container:hover{
  /* 不起作用 */
  animation-play-state: paused;
 }
 .marquee_text{
  color:#333;
  font-size: 28rpx;
  display: inline-block;
  white-space: nowrap;
  animation-name: around;
  animation-duration: 10s; /*過渡時間*/
  animation-iteration-count: infinite;
  animation-timing-function:linear;
 }
 .bulletin_box_img2{
  position: absolute;
  width: 60rpx;
  height: 54rpx;
  z-index: 9;
  padding-left: 15rpx;
  padding-right: 15rpx;
  margin-top: 14rpx;
  background: #fff;
}
.bulletin_box_img2 image{
  width: 100%;
  height: 100%;
}

 

 

 

 

參考鏈接:https://www.jb51.net/article/160412.htm


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM