微信小程序仿京東分類 scoll-view組建實(shí)現(xiàn)

先看看效果



.wxml :

<view class="container">? <!--左側(cè)欄-->? <scroll-view class='scroll_left' scroll-y="true">? ? <view class="nav_left">? ? ? <block wx:for="{{list}}" wx:for-index="idx" wx:for-item="itemName" wx:key="*this">? ? ? ? <!--當(dāng)前項(xiàng)的id等于item項(xiàng)的id臂拓,那個(gè)就是當(dāng)前狀態(tài)-->? ? ? ? <!--用data-index記錄這個(gè)數(shù)據(jù)在數(shù)組的下標(biāo)位置彭沼,使用data-id設(shè)置每個(gè)item的id值,供打開右側(cè)側(cè)滑欄使用-->? ? ? ? <view class="nav_left_items {{curNav == idx ? 'active' : ''}}" bindtap="switchRightTab" data-index="{{index}}" data-id="{{item.id}}" id="{{idx}}">? ? ? ? ? <view class="{{curNav == idx ? 'isSelect' : 'noSelect'}}" data-index="{{index}}" data-id="{{item.id}}" id="{{idx}}"></view>? ? ? ? ? <view data-index="{{index}}" data-id="{{item.id}}" id="{{idx}}" class="item-name {{curNav == idx ? 'item-name-select' : ''}}" bindtap="switchRightTab">{{itemName[0].name}}</view>? ? ? ? </view>? ? ? </block>? ? </view>? </scroll-view>? <!--右側(cè)欄-->? <!--如果使用 scroll-into-view 屬性阴孟,必須設(shè)置 scroll-view 的高度浮还,且最好是動(dòng)態(tài)獲取屏幕高度 -->? <!-- scroll-into-view 屬性 值應(yīng)為某子元素id(id不能以數(shù)字開頭)稽坤。設(shè)置哪個(gè)方向可滾動(dòng)剩拢,則在哪個(gè)方向滾動(dòng)到該元素 -->? <scroll-view scroll-y="true" class="scroll_right" style="height:{{winHeight}}px;" scroll-into-view="{{scrollTopId}}" scroll-with-animation="true">? ? <view class="nav_right">? ? ? <view class='mink' wx:for="{{list}}" wx:for-index="idx" wx:for-item="itemName" wx:key="*this" bindscroll="scrollTop">? ? ? ? <view class='header-img' id='{{idx}}'>? ? ? ? ? <image src='http://qn.sdhui.net/file/upload/96d72afaa5634ece9dba5eb9370af0b6'></image>? ? ? ? </view>? ? ? ? <view class='minl'>{{itemName[0].name}}</view>? ? ? ? <view class='view-items'> ? ? ? ? ? <view class='view-items-item' wx:for="{{itemName}}" wx:if="{{index>0}}">? ? ? ? ? <navigator url="../detail/detail?id={{item.desc}}" hover-class="other-navigator-hover">? ? ? ? ? ? <view class='view-items-item-view1'>? ? ? ? ? ? ? <image src="{{item.picture}}"></image>? ? ? ? ? ? </view>? ? ? ? ? ? <view class='view-items-item-view2'>? ? ? ? ? ? ? <text>{{item.desc}}</text>? ? ? ? ? ? </view>? ? ? ? ? ? </navigator>? ? ? ? ? </view> ? ? ? ? </view> ? ? ? </view>? ? </view>? </scroll-view></view>

.js:

var list = require('../../utils/list.js')const app = getApp();Page({? data: {? ? // 左側(cè)點(diǎn)擊類樣式? ? curNav: 'A1',? },? onReady: function () {? ? // 生命周期函數(shù)--監(jiān)聽頁(yè)面初次渲染完成? ? var listChild1 = list.List[0];? ? console.log(listChild1)? ? var that = this;? ? // 獲取可視區(qū)高度? ? wx.getSystemInfo({? ? ? success: function (res) {? ? ? ? that.setData({? ? ? ? ? list: listChild1,? ? ? ? ? winHeight: res.windowHeight,? ? ? ? })? ? ? }? ? })? },? //點(diǎn)擊左側(cè) tab ,右側(cè)列表相應(yīng)位置聯(lián)動(dòng) 置頂? switchRightTab: function (e) {? ? var id = e.target.id;? ? console.log(id)? ? this.setData({? ? ? // 動(dòng)態(tài)把獲取到的 id 傳給 scrollTopId? ? ? scrollTopId: id,? ? ? // 左側(cè)點(diǎn)擊類樣式? ? ? curNav: id,? ? })? }})



.css:

.container {? position: relative;?? width: 100%;?? height: 1220rpx;?? background-color:white;?? color: #939393;?}? /*左側(cè)欄主盒子*/?.nav_left{?? /*設(shè)置行內(nèi)塊級(jí)元素(沒使用定位)*/?? display: inline-block;?? width: 100%;?? height: 100%;?? /*主盒子設(shè)置背景色為灰色*/?? background: #fff;?? text-align: center;?? /* position: fixed;? */? left: 0;? top: 0;? /* border-top: 1rpx solid #dedede; 上側(cè)線條*/}?.isSelect{? height: 50%;? width: 2%;? background: red; }.item-name{? width: 98%;? display: flex;? justify-content: center;? align-items: center;? background: #f0f4f7;}.item-name-select{? width: 98%;? ? background: #fff;? ? font-weight: bold;? color: #ed1000;}/*左側(cè)欄list的item*/?.nav_left .nav_left_items{?? background: #fff;? /*每個(gè)高30px*/?? height: 100rpx;?? /*垂直居中*/?? line-height: 100rpx;?? /*再設(shè)上下padding增加高度够话,總高42px*/?? /* padding: 15rpx 0;? */? /*只設(shè)下邊線*/?? /* border-bottom: 1px solid #dedede;? */? display: flex;? flex-direction: row;? /*文字14px*/? ? align-items: center;? font-size: 26rpx;? color: #8b8888;?? /* font-weight:? */}?/*左側(cè)欄list的item被選中時(shí)*/?.nav_left .nav_left_items.active{?? /*背景色變成白色*/?? /* background: #f0f4f7; */? color: #ed1000;? /* border-left: 3px? solid? #ed1000;? */ }? /*右側(cè)欄主盒子*/?.scroll_right{?? /*右側(cè)盒子使用了絕對(duì)定位*/?? position: fixed;? top: 0;?? right: 0;? overflow: auto;? flex: 1;?? /*寬度75%蓝翰,高度占滿光绕,并使用百分比布局*/?? width: 75%;?? height: 100%;?? padding: 0 20rpx 20rpx 20rpx;?? box-sizing: border-box;?}/* 隱藏滾動(dòng)條 */::-webkit-scrollbar {? width: 0;? height: 0;? color: transparent;}.mink::after{? display:block;content:'';clear:both; }/* .jiul,.jiul image{? width: 100%;? height: 300rpx; } */.minl{? font-weight: bold;? font-size: 29rpx;? color: rgb(17, 16, 16);? text-align: left;? line-height: 60rpx;? float: left;? display: flex;? justify-content: center;? align-items: center; ? /* background: #f0f4f7;? */? width: 100%;? height: 50rpx;}.mink{? width: 100%;? background: #fff;? height: 100%;? /* border: 1rpx solid #dedede; */}/*右側(cè)欄list的item*/?.nav_right_items{?? /*浮動(dòng)向左*/?? float: left;?? /*每個(gè)item設(shè)置寬度是33.33%*/?? width: 50%;? /* height: 160rpx;? */? text-align: center;? color: #ed1000;}?.nav_right_items image{?? /*被圖片設(shè)置寬高*/?? width: 60px;?? height: 50px;? margin-top: 15rpx;}?.nav_right_items text{?? /*給text設(shè)成塊級(jí)元素*/?? display: block;?? margin-top: 5rpx;?? margin-bottom: 10rpx;? font-size: 26rpx;?? /*設(shè)置文字溢出部分為...*/?? overflow: hidden;?? white-space: nowrap;?? text-overflow: ellipsis;?}/** 自定義其他點(diǎn)擊態(tài)樣式類 **/.other-navigator-hover{? background:#dedede;}.scroll_left{? width:25%;? height:100%;? background:#fff;? text-align:center;? position: fixed;? left: 0;top: 0}.header-img{? height: 100px;? width: 100%;border-radius: 10rpx;}.header-img image{? width: 100%;? height: 100%;? border-radius: 10rpx; }.view-items{? width: 100%;? height: 100%;? display: flex;? flex-wrap: wrap;? margin-bottom: 70rpx;}.view-items-item{? width:50%;? height: 100%;? display: flex;? flex-direction: column;? margin-top: 15rpx;}.view-items-item-view1{display: flex;justify-content: center;align-items: center;margin-bottom: 8rpx;}.view-items-item-view2{? display: flex;justify-content: center;align-items: center;}.view-items-item-view1 image{ ? width: 60px;?? height: 60px;? margin-top: 15rpx;}.view-items-item-view2 text{? font-size: 26rpx;? ?}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市畜份,隨后出現(xiàn)的幾起案子诞帐,更是在濱河造成了極大的恐慌,老刑警劉巖爆雹,帶你破解...
    沈念sama閱讀 217,542評(píng)論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件停蕉,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡钙态,警方通過查閱死者的電腦和手機(jī)慧起,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,822評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來册倒,“玉大人蚓挤,你說我怎么就攤上這事∈JВ” “怎么了屈尼?”我有些...
    開封第一講書人閱讀 163,912評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵册着,是天一觀的道長(zhǎng)拴孤。 經(jīng)常有香客問我,道長(zhǎng)甲捏,這世上最難降的妖魔是什么演熟? 我笑而不...
    開封第一講書人閱讀 58,449評(píng)論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮司顿,結(jié)果婚禮上芒粹,老公的妹妹穿的比我還像新娘。我一直安慰自己大溜,他們只是感情好化漆,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,500評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著钦奋,像睡著了一般座云。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上付材,一...
    開封第一講書人閱讀 51,370評(píng)論 1 302
  • 那天朦拖,我揣著相機(jī)與錄音,去河邊找鬼厌衔。 笑死璧帝,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的富寿。 我是一名探鬼主播睬隶,決...
    沈念sama閱讀 40,193評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼锣夹,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了理疙?” 一聲冷哼從身側(cè)響起晕城,我...
    開封第一講書人閱讀 39,074評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎窖贤,沒想到半個(gè)月后砖顷,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,505評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡赃梧,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,722評(píng)論 3 335
  • 正文 我和宋清朗相戀三年滤蝠,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片授嘀。...
    茶點(diǎn)故事閱讀 39,841評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡物咳,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出蹄皱,到底是詐尸還是另有隱情览闰,我是刑警寧澤,帶...
    沈念sama閱讀 35,569評(píng)論 5 345
  • 正文 年R本政府宣布巷折,位于F島的核電站压鉴,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏锻拘。R本人自食惡果不足惜油吭,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,168評(píng)論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望署拟。 院中可真熱鬧婉宰,春花似錦、人聲如沸推穷。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,783評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)馒铃。三九已至蟹腾,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間骗露,已是汗流浹背岭佳。 一陣腳步聲響...
    開封第一講書人閱讀 32,918評(píng)論 1 269
  • 我被黑心中介騙來泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留萧锉,地道東北人珊随。 一個(gè)月前我還...
    沈念sama閱讀 47,962評(píng)論 2 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親叶洞。 傳聞我的和親對(duì)象是個(gè)殘疾皇子鲫凶,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,781評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • 實(shí)現(xiàn)該功能的思路:通過點(diǎn)擊左側(cè)滑欄的某一項(xiàng),獲取到該元素?cái)y帶的 id 衩辟,然后動(dòng)態(tài)傳給右側(cè)滑欄的 scroll-in...
    _vb閱讀 627評(píng)論 0 1
  • // ps:先上代碼 后面有時(shí)間再補(bǔ)備注 效果圖 wxml <view class="container"> <v...
    pengkiw閱讀 9,389評(píng)論 1 7
  • 小程序 通訊錄效果圖 三個(gè)主要部分 : 1)右側(cè)定位導(dǎo)航 2)左側(cè)內(nèi)容部分 3)頂部固定導(dǎo)航 wxml 部分 <v...
    pengkiw閱讀 8,206評(píng)論 0 8
  • 每天的學(xué)習(xí)記錄螟炫,可能有的地方寫的不對(duì),因?yàn)閯倢W(xué)艺晴,以后發(fā)現(xiàn)錯(cuò)的話會(huì)回來改掉整體流程 https://develope...
    有點(diǎn)健忘閱讀 4,671評(píng)論 0 7
  • 當(dāng)所有人都用絕望的眼光來看你時(shí)昼钻,你也依然可以按照自己的方式生活,不卑不亢封寞,卻也充滿希望然评。
    絢爛的陽(yáng)光閱讀 106評(píng)論 0 0