首頁  >  文章  >  微信小程式  >  微信小程式內如何做出跑馬燈效果(附代碼)

微信小程式內如何做出跑馬燈效果(附代碼)

php中世界最好的语言
php中世界最好的语言原創
2018-06-01 09:22:394932瀏覽

這次帶給大家微信小程式內如何做出跑馬燈效果(附代碼),微信小程式內做出跑馬燈效果的注意事項有哪些,下面就是實戰案例,一起來看一下。

一:功能介紹及講解

實現的跑馬燈(跑馬燈裡面顯示文章的title)的效果,並在右側有個查看文章的按鈕,按鈕綁定當前的跑馬燈資訊的id,點擊按鈕後根據id跳到對應的文章詳情頁;

這裡值得注意的點是我用了 swiper元件的bindchange 事件來取得到目前資訊的陣列下標,實現了動態改變檢視按鈕綁定資訊id值的效果;

如果還有不懂的地方歡迎加入(173683895)微信小程式開發交流群。

二:效果圖:

#三:完整原始碼

1.封裝成一個元件:

<!-- //滚动 --> 
<template name="roll"> 
 <block> 
   <navigator url=&#39;../details/details2/detail2?artical_id={{newsId}}&#39;> 
    <view class=&#39;chakan&#39;>查看</view> 
   </navigator> 
  <view class=&#39;sx_lunbo page_row&#39;> 
   <text class=&#39;red&#39;>公告</text> 
   <swiper class=&#39;sx_swiper page_row&#39; autoplay interval="5000" duration="3000" bindchange="newsId" data-newsId=&#39;{{item.id}}&#39; circular> 
    <swiper-item wx:for="{{news}}" wx:key=""> 
     <view class=&#39;reds&#39;>{{item.title}} 
     </view> 
    </swiper-item> 
   </swiper> 
  </view> 
 </block> 
</template>
.sx_lunbo { 
 width: 100%; 
 height: 60rpx; 
 border-bottom: solid 1px #eee; 
} 
.chakan{ 
 padding-left: 25rpx; 
 right: 20rpx; 
 clear: both; 
 position:absolute;  
 height: 40rpx; 
 margin-top: 10rpx; 
 color: #f63; 
 border:solid 1px #f63; 
 border-radius:5rpx; 
 padding: 0rpx 10rpx 0rpx 10rpx; 
 font-size: 28rpx 
} 
.sx_swiper { 
 width: 550rpx; 
 margin-top: 10rpx; 
} 
.sx_swiper swiper-item{ 
  height: 40rpx 
 } 
.reds { 
 overflow: hidden; 
 text-overflow: ellipsis; 
 white-space:nowrap; 
 width:500rpx; 
 font-size: 28rpx; 
 height: 40rpx; 
} 
.red { 
 font-size: 24rpx; 
 color: white; 
 width: 60rpx; 
 height: 40rpx; 
 line-height: 40rpx; 
 background: blue; 
 padding-left: 10rpx; 
 margin: 10rpx; 
 border-radius: 10rpx; 
}

2.在頁面呼叫:

<import src="../template/roll/roll.wxml" /> 
<template is="roll" data="{{news,newsId}}" />
@import "../template/roll/roll.wxss";
newsId: function (e) { 
 var that = this 
 var item = e.detail.current; 
 this.setData({ 
  newsId:that.data.news[item].id 
 }) 
},

3.news的資料:

#相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!

推薦閱讀:

JS反射與依賴注入使用案例分析

如何在微信小程式內開發驗證碼密碼輸入框功能

以上是微信小程式內如何做出跑馬燈效果(附代碼)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn