最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

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

<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),根據(jù)屏幕尺寸計算單個字體的寬度
? ? // 不知道為什么用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只多出來一點點導(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);
? },

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

相關(guān)文章

最新評論

青浦区| 连云港市| 万安县| 厦门市| 张家界市| 三亚市| 汤阴县| 淄博市| 遂昌县| 五台县| 文化| 泽库县| 新干县| 水城县| 鄢陵县| 福安市| 台东市| 梁平县| 汨罗市| 滦南县| 洞口县| 神池县| 怀化市| 康乐县| 洮南市| 柏乡县| 平潭县| 乐山市| 虹口区| 穆棱市| 泰兴市| 类乌齐县| 玉环县| 神农架林区| 深泽县| 甘德县| 巴青县| 大港区| 吉木乃县| 建阳市| 大丰市|