欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序實現輪播圖標題跑馬燈

 更新時間:2022年06月24日 14:19:04   作者:Zmikoo成長之路  
這篇文章主要為大家詳細介紹了微信小程序實現輪播圖標題跑馬燈,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了微信小程序實現輪播圖標題跑馬燈的具體代碼,供大家參考,具體內容如下

微信小程序做輪播圖,輪播圖下的標題如果不長不需要跑馬燈效果,過長的無法顯示全的則添加跑馬燈效果

<swiper class="swiper" current="0" bindchange="onSlideChange">
? ? <swiper-item wx:for='{{carouselImgArr}}' wx:key='index'>
? ? ? <image?
? ? ? ? ? src='{{item.image}}'?
? ? ? ? ? mode='heightFix'
? ? ? ? ? class="swiper-item-img">
? ? ? </image>
? ? ? <view class="swiper-item-tit" wx:if='{{item.title}}'>
? ? ? ? <view class="swiper-tit-inner {{(currImgIndex - 1) == index ? 'active' : ''}}"?
? ? ? ? ? ? ? style='transform:translate({{ ((currImgIndex - 1) == index ? carouselTitLeft : 0) + "px" }})'>
? ? ? ? ? {{item.title}}
? ? ? ? </view>
? ? ? </view>
? ? </swiper-item>
</swiper>
.swiper{
? position: relative;
? height: 430rpx;
? padding: 0px;
? margin: 0px;
}
.swiper image{
? height: 430rpx;
? position: absolute;
? left:50%;
? top:50%;
? transform: translate(-50%,-50%);
}
.swiper-item-tit{
? position: absolute;
? bottom: 0rpx;
? left:0rpx;
? z-index: 2;
? height: 80rpx;
? line-height: 80rpx;
? color:#fff;
? width:100%;
? /* overflow: hidden; */
? /* text-overflow: ellipsis; */
? background-color: rgba(0,0,0,0.5);
}
.swiper-item-tit .swiper-tit-inner{
? text-align: center;
? white-space: nowrap;
}?
data: {
? ? carouselImgArr: [{
?? ??? ?image:'../../image/1.png',title:'標題',
?? ?},{
?? ??? ?image:'../../image/1.png',title:'標題標題標題標題標題標題標題標題標題',
?? ?},{
?? ??? ?image:'../../image/1.png',title:'標題',
?? ?} ],
? ? carouselTitleLength:[2,18,2],// 輪播圖標題的文字長度
? ? carouselTitLeft:0,
? ? currImgIndex: 1,
? ? windowWidth: wx.getSystemInfoSync().windowWidth
? },
onSlideChange(e) {
? ? this.setData({
? ? ? currImgIndex: e.detail.current + 1,
? ? ? carouselTitLeft: 0
? ? });
? ? this.initMarqueen();
? },
? initMarqueen() {
? ? clearInterval(marqueenTimer);
? ? var self = this;
? ? var boxWidth,textWidth;
? ? var query = wx.createSelectorQuery();
? ? // query.select('.swiper-item-tit').fields({size:true},function(res){
? ? // ? boxWidth = res.width;
? ? // }).exec();
? ? // query.select('.active').fields({size:true},function(res){
? ? // ? textWidth = res.width;
? ? // }).exec();
? ? setTimeout(function(){
? ? ? let boxWidth = self.data.windowWidth;// 屏幕尺寸寬等于字體box寬,所以這里用屏幕寬替代了query獲取的寬
? ? ? let scale = boxWidth / 375;// 以屏幕尺寸為375為標準(375下字體寬約為14),根據屏幕尺寸計算單個字體的寬度
? ? // 不知道為什么用query 獲取的textWidth始終等于boxWidth的寬度,不得已只能使用文字長度乘以文字寬度來計算boxWidth。而
? ? ? let textWidth = self.data.carouselTitleLength[self.data.currImgIndex - 1] * (14*scale);
? ? ? console.log(scale,boxWidth,textWidth);
? ? ? if (textWidth - 3*scale > boxWidth) {// 減去3*scale防止textWidth只多出來一點點導致文字左右震蕩
? ? ? ? let stayTime = 1000;
? ? ? ? let endStay = true;
? ? ? ? marqueenTimer = setInterval(function(){
? ? ? ? ? let currLeft = self.data.carouselTitLeft;
? ? ? ? ? if (stayTime !== 0) {
? ? ? ? ? ? stayTime = stayTime - 30;
? ? ? ? ? ? console.log('stay')
? ? ? ? ? } else if (currLeft > boxWidth - textWidth) {
? ? ? ? ? ? self.setData({
? ? ? ? ? ? ? carouselTitLeft: currLeft - 2
? ? ? ? ? ? });
? ? ? ? ? } else {
? ? ? ? ? ? if (endStay) {// 跑馬燈結尾停留1s;
? ? ? ? ? ? ? endStay = false;
? ? ? ? ? ? ? stayTime = 1200;
? ? ? ? ? ? ? return;
? ? ? ? ? ? }
? ? ? ? ? ? self.setData({
? ? ? ? ? ? ? carouselTitLeft: 0
? ? ? ? ? ? });
? ? ? ? ? ? stayTime = 1200;// 回到跑馬燈開頭再停留1s;
? ? ? ? ? ? endStay = true;
? ? ? ? ? }
? ? ? ? },100)
? ? ? }
? ? },100);
? },

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • JS模擬鍵盤打字效果的方法

    JS模擬鍵盤打字效果的方法

    這篇文章主要介紹了JS模擬鍵盤打字效果的方法,涉及javascript鼠標事件及字符串操作的相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-08-08
  • 原生js簡單實現放大鏡特效

    原生js簡單實現放大鏡特效

    這篇文章主要為大家詳細介紹了原生js簡單實現放大鏡特效,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • 學習JS中的DOM節(jié)點以及操作

    學習JS中的DOM節(jié)點以及操作

    本篇文章給大家整理了關于JS中DOM節(jié)點的相關知識點以及代碼實例,有興趣的朋友可以跟著學習下。
    2018-04-04
  • Js中FileReader讀取文件內容方法詳解(async/await)

    Js中FileReader讀取文件內容方法詳解(async/await)

    這篇文章主要給大家介紹了關于Js中FileReader讀取文件內容(async/await)的相關資料,FileReader是前端進行文件處理的一個重要的Api,特別是在對圖片的處理上,如果你想知道圖片的處理原理,你就永遠不可能繞過它,需要的朋友可以參考下
    2023-11-11
  • Node.js實戰(zhàn) 建立簡單的Web服務器

    Node.js實戰(zhàn) 建立簡單的Web服務器

    本章我們同樣通過實戰(zhàn)的演練,利用Node.js建立一個簡單的Web服務器
    2012-03-03
  • 詳解JavaScript中typeof與instanceof用法

    詳解JavaScript中typeof與instanceof用法

    typeof用以獲取一個變量或者表達式的類型而instanceof用于判斷一個變量是否某個對象的實例,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友參考下吧
    2018-10-10
  • 使用getBoundingClientRect方法實現簡潔的sticky組件的方法

    使用getBoundingClientRect方法實現簡潔的sticky組件的方法

    本文介紹這種組件的實現思路,并提供一個同時支持將sticky元素固定在頂部或底部的具體實現,由于這種組件在網站中非常常見,所以有必要掌握它的實現方式,以便在有需要的時候基于它的思路寫出功能更多的組件出來
    2016-03-03
  • JS采用絕對定位實現回到頂部效果完整實例

    JS采用絕對定位實現回到頂部效果完整實例

    這篇文章主要介紹了JS采用絕對定位實現回到頂部效果,以完整實例形式分析了JS定位到頁面頂部功能的實現方法,涉及javascript動態(tài)操作頁面元素與屬性的相關技巧,需要的朋友可以參考下
    2016-06-06
  • Bootstrap模態(tài)框調用功能實現方法

    Bootstrap模態(tài)框調用功能實現方法

    這篇文章主要介紹了Bootstrap模態(tài)框調用功能實現方法的相關資料,非常不錯,具有參考借鑒價值,感興趣的朋友一起看看吧
    2016-09-09
  • gulp-htmlmin壓縮html的gulp插件實例代碼

    gulp-htmlmin壓縮html的gulp插件實例代碼

    這篇文章主要介紹了gulp-htmlmin壓縮html的gulp插件實例代碼的相關資料,需要的朋友可以參考下
    2016-06-06

最新評論