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

微信小程序?qū)崿F(xiàn)菜單左右聯(lián)動效果

 更新時間:2022年07月17日 14:16:27   作者:墨客的全棧之路  
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)菜單左右聯(lián)動效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)菜單左右聯(lián)動效果的具體代碼,供大家參考,具體內(nèi)容如下

原理

首先是獲取數(shù)據(jù),并且獲取數(shù)據(jù)的長度(需要根據(jù)長度來計算元素的高度),通過遍歷數(shù)據(jù)的內(nèi)容通過題目和元素個數(shù)的相加得到高度,當(dāng)消失高度小于等于某個元素的高度就設(shè)定索引值給左邊的菜單目錄實(shí)現(xiàn)右邊滑動左邊聯(lián)動,左邊的菜單點(diǎn)擊事件聯(lián)動比較簡單就不說

代碼實(shí)現(xiàn)

wxml

<view class="menu">
? ? ? ? <view class="left-box">
? ? ? ? ? ? <scroll-view class="left_menu" scroll-with-animation ?scroll-y="true" scroll-into-view="{{leftViewId}}">
? ? ? ? ? ? ? ? <text class="menu-item {{index==currentIndex?'menu-active':''}}" wx:for="{{navList}}" wx:key="this" data-id="menu{{index}}" data-i="{{index}}" bindtap="changeMenu">{{item.c_name}}</text>
? ? ? ? ? ? </scroll-view>
? ? ? ? </view>
? ? ? ? <view class="right-box">
? ? ? ? ? ? <scroll-view class="right_menu" scroll-y='true' ?scroll-with-animation scroll-into-view="{{rightViewId}}" ?bindscroll="getScroll" enable-flex>
? ? ? ? ? ? ? ? <view wx:for="{{navList}}" wx:key="this" class='pro-item' id="menu{{index}}">
? ? ? ? ? ? ? ? ? ? <view class="right_menu_head">{{item.c_name}}</view>
? ? ? ? ? ? ? ? ? ? <view class="list-box">
? ? ? ? ? ? ? ? ? ? ? ? <view class="menu_list" wx:for-item='items' wx:for="{{item.list}}" wx:key="this">
? ? ? ? ? ? ? ? ? ? ? ? <image src="{{items.url}}"></image>
? ? ? ? ? ? ? ? ? ? ? ? <view>{{items.goodsName}}</view>
? ? ? ? ? ? ? ? ? ? </view>
? ? ? ? ? ? ? ? </view>
? ? ? ? ? ? ? ? </view>
? ? ? ? ? ? </scroll-view>
? ? ? ? </view>
</view>

wxss,這里使用的是less語法,vscode插件可編譯

.menu{
? ? .left-box{
? ? ? ? width: 180rpx;
? ? ? ? border-right: 1px solid #dfdfdf;
? ? ? ? position: fixed;
? ? ? ? left: 0;
? ? ? ? z-index: 10;
? ? ? ? top: 370rpx;
? ? ? ? box-sizing: border-box;
? ? ? ? height: 90%;
? ? ? ? background: #f0f0f0;

? ? ? ? .menu-item{
? ? ? ? ? ? display: inline-block;
? ? ? ? ? ? width: 180rpx;
? ? ? ? ? ? height: 88rpx;
? ? ? ? ? ? font-size: 26rpx;
? ? ? ? ? ? line-height: 88rpx;
? ? ? ? ? ? background: #fff;
? ? ? ? ? ? text-align: center;
? ? ? ? ? ? border-bottom: 1px solid #dfdfdf;
? ? ? ? }

? ? ? ? .menu-active{
? ? ? ? ? ? background: #f0f0f0;
? ? ? ? ? ? border-left: 10rpx ?solid #333999;
? ? ? ? }
? ? }
? ??
? ? .right-box{
? ? ? ? width: 74%;
? ? ? ? position: fixed;
? ? ? ? top: 360rpx;
? ? ? ? height: 77%;
? ? ? ? right: 0;
? ? ? ? border-left: 20rpx;
? ? ? ? box-sizing: border-box;
? ? ? ? margin-top: 20rpx;

? ? ? ? .right_menu{
? ? ? ? ? ? height: 100%;
? ? ? ? ? ? box-sizing: border-box;

? ? ? ? ? ? .pro-item{

? ? ? ? ? ? ? ? .right_menu_head{
? ? ? ? ? ? ? ? ? ? height: 80rpx;
? ? ? ? ? ? ? ? ? ? line-height: 80rpx;
? ? ? ? ? ? ? ? ? ? font-size: 26rpx;
? ? ? ? ? ? ? ? ? ? font-weight: 600;
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? &:last-child{
? ? ? ? ? ? ? ? ? ? margin-bottom: 156rpx;
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? .list-box{
? ? ? ? ? ? ? ? ? ? width: 100%;
? ? ? ? ? ? ? ? ? ? // min-height: 380rpx;
? ? ? ? ? ? ? ? ? ? display: flex;
? ? ? ? ? ? ? ? ? ? flex-wrap: wrap;
? ? ? ? ? ? ? ? ? ? background: #fff;
? ? ? ? ? ? ? ? ? ? box-sizing: border-box;
? ? ? ? ? ? ? ? ? ? border-radius: 10rpx;
? ? ? ? ? ? ? ? ? ? font-size: 20rpx;

? ? ? ? ? ? ? ? ? ? .menu_list{
? ? ? ? ? ? ? ? ? ? ? ? width: 33.3%;
? ? ? ? ? ? ? ? ? ? ? ? font-size: 20rpx;
? ? ? ? ? ? ? ? ? ? ? ? padding: 20rpx 0;
? ? ? ? ? ? ? ? ? ? ? ? text-align: center;
? ? ? ? ? ? ? ? ? ? ? ? font-style: '微軟雅黑';

? ? ? ? ? ? ? ? ? ? ? ? image{
? ? ? ? ? ? ? ? ? ? ? ? ? ? width: 100rpx;
? ? ? ? ? ? ? ? ? ? ? ? ? ? height: 100rpx;
? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? view{
? ? ? ? ? ? ? ? ? ? ? ? ? ? color: #333;
? ? ? ? ? ? ? ? ? ? ? ? ? ? text-overflow: ellipsis;
? ? ? ? ? ? ? ? ? ? ? ? ? ? white-space: nowrap;
? ? ? ? ? ? ? ? ? ? ? ? ? ? overflow: hidden;
? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }
}

js文件

data:{
?? ?navList:[..],//數(shù)據(jù)
?? ?currentIndex: 0,//左邊對應(yīng)的索引
? ? rightViewId: '',//點(diǎn)擊事件右邊的索引
}

getScroll(e) {//微信小程序中綁定滑動函數(shù),每滑動一下都會觸發(fā)
? ? ? ? let top = e.detail.scrollTop,
? ? ? ? ? ? h = 0,
? ? ? ? ? ? _this = this;


? ? ? ? for (let i = 0; i < this.data.navList.length; i++) {
? ? ? ? ? ? let dishSize = this.data.navList[i].list.length;//獲取數(shù)據(jù)對應(yīng)展示商品的json
? ? ? ? ? ? h += 38 + parseInt(dishSize / 3 * 80);//獲取當(dāng)前元素的高度,38是標(biāo)題高度,80是元素高度

? ? ? ? ? ? if (top <= h) {//滿足條件立刻停止循環(huán),就會一直停留再當(dāng)前索引,不滿足當(dāng)前就會自動到下一個菜單
? ? ? ? ? ? ? ? _this.setData({
? ? ? ? ? ? ? ? ? ? currentIndex: i
? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }

? ? ? ? }

? ? },
? ? changeMenu(e) {
? ? ? ? console.log(this.data.heightArr, this.data.topArr);

? ? ? ? this.setData({
? ? ? ? ? ? currentIndex: e.currentTarget.dataset.i,
? ? ? ? ? ? rightViewId: e.currentTarget.dataset.id
? ? ? ? })

? ? }

展示圖片

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

相關(guān)文章

最新評論