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

微信小程序?qū)崿F(xiàn)輪播圖標(biāo)題跑馬燈

 更新時(shí)間:2022年06月24日 14:19:04   作者:Zmikoo成長(zhǎng)之路  
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)輪播圖標(biāo)題跑馬燈,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)輪播圖標(biāo)題跑馬燈的具體代碼,供大家參考,具體內(nèi)容如下

微信小程序做輪播圖,輪播圖下的標(biāo)題如果不長(zhǎng)不需要跑馬燈效果,過長(zhǎng)的無(wú)法顯示全的則添加跑馬燈效果

<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:'標(biāo)題',
?? ?},{
?? ??? ?image:'../../image/1.png',title:'標(biāo)題標(biāo)題標(biāo)題標(biāo)題標(biāo)題標(biāo)題標(biāo)題標(biāo)題標(biāo)題',
?? ?},{
?? ??? ?image:'../../image/1.png',title:'標(biāo)題',
?? ?} ],
? ? carouselTitleLength:[2,18,2],// 輪播圖標(biāo)題的文字長(zhǎng)度
? ? 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為標(biāo)準(zhǔn)(375下字體寬約為14),根據(jù)屏幕尺寸計(jì)算單個(gè)字體的寬度
? ? // 不知道為什么用query 獲取的textWidth始終等于boxWidth的寬度,不得已只能使用文字長(zhǎng)度乘以文字寬度來(lái)計(jì)算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只多出來(lái)一點(diǎn)點(diǎn)導(dǎo)致文字左右震蕩
? ? ? ? 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) {// 跑馬燈結(jié)尾停留1s;
? ? ? ? ? ? ? endStay = false;
? ? ? ? ? ? ? stayTime = 1200;
? ? ? ? ? ? ? return;
? ? ? ? ? ? }
? ? ? ? ? ? self.setData({
? ? ? ? ? ? ? carouselTitLeft: 0
? ? ? ? ? ? });
? ? ? ? ? ? stayTime = 1200;// 回到跑馬燈開頭再停留1s;
? ? ? ? ? ? endStay = true;
? ? ? ? ? }
? ? ? ? },100)
? ? ? }
? ? },100);
? },

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論