微信小程序 模仿通訊錄

小程序 通訊錄效果圖

三個(gè)主要部分 : 1)右側(cè)定位導(dǎo)航? ?2)左側(cè)內(nèi)容部分? ?3)頂部固定導(dǎo)航



wxml 部分

<view>

<!-- 左側(cè)列表內(nèi)容部分 -->

<scroll-view class="contentList" enable-back-to-top scroll-into-view="{{toView}}" scroll-y="true" scroll-with-animation="true" bindscroll="onPageScroll">

????<view wx:for="{{listMain}}" wx:for-item="group" wx:key="{{group.id}}" id="{{ 'inTo'+group.id}}" data-id='{{group.id}}'>

????????<view class="address_top">{{group.region}}</view>

????????<view wx:for="{{group.items}}" wx:for-item="item" wx:key="{{item.brandId}}">

????????????????<view class="address_bottom" data-id='{{item.brandId}}'>{{item.name}}</view>

????????</view>

????</view>

</scroll-view>

<!-- 頂部固定分類(lèi) -->

<view class="list-fixed {{fixedTitle==null ? 'hide':''}}" style="transform:translate3d(0,{{fixedTop}}px,0);">

????<view class="fixed-title"> {{fixedTitle}} </view>

</view>

<!-- 右側(cè)字母導(dǎo)航 -->

<view class="orientation_region">

????<view class="orientation">#</view>

????<block wx:for="{{listMain}}" wx:key="{{item.id}}">

????????<view class="orientation_city {{isActive==item.id ? 'active':'' }}" bindtap="scrollToViewFn" data-id="{{item.id}}">

????????????????{{item.region}}

????????</view>

????</block>

</view>

</view>

wxss

page {

????height: 100%;?

}

.search {

????display: flex;

????position: relative;

????padding: 20rpx 30rpx;

????background: #fff;

}

.search .input-wrapper {

????background: #f2f2f2;

????width: 80%;

????display: flex;

????height: 68rpx;

????border-radius: 68rpx;

????position: relative;

}

.search .input-wrapper input {

????height: 68rpx;

????width: calc(100% - 84rpx);

????margin-left: 20rpx;

}

.search .input-wrapper .searchImg {

????width: 32rpx;

????height: 32rpx;

????margin-left: 32rpx;

????position: relative;

????top: 50%;

????margin-top: -18rpx;

}

.search .input-wrapper .delImg {

????width: 32rpx;

????height: 32rpx;

????position: relative;

????top: 50%;

????margin-top: -16rpx;

????right: 32rpx;

????vertical-align: top;

}

.search .searchBtn {

????color: #348efa;

????width: 20%;

????text-align: center;

????line-height: 68rpx;

????font-size: 36rpx;

}

.currentCity {

????padding: 20rpx 30rpx;

}

.currentCity .subTitle {

????font-weight: bold;

????font-size: 28rpx;

}

.currentCity .city {

????border: 1px solid #ccc;

????display: inline-block;

????padding: 10rpx 40rpx;

????border-radius: 8rpx;

????margin-top: 20rpx;

}

.currentCity .city image {

????width: 26rpx;

????height: 32rpx;

????vertical-align: top;

}

.hotCity {

????padding: 0 80rpx 0 30rpx;

}

.hotCity .subTitle {

????font-weight: bold;

}

.hotCity .content {

????display: flex;

????flex-wrap: wrap;

????justify-content: space-between;

}

.hotCity .content {

????margin-top: 20rpx;

}

.hotCity .content .unit {

????width: 30%;

????border: 1px solid#CCCCCC;

????text-align: center;

????border-radius: 8rpx;

????padding: 10rpx 0;

????margin-bottom: 20rpx;

}

.allCity { height:50px; line-height: 50px; padding: 0 30rpx; font-weight: bold; font-size: 30rpx;}

.contentList { padding-bottom: 20rpx; box-sizing: border-box; height: 100%; bottom: 0; position: absolute;}

.location { width: 100%;}

.location_top { height: 76rpx; line-height: 76rpx; background: #f4f4f4; color: #606660; font-size: 28rpx; padding: 0 20rpx;}

.location_bottom { height: 140rpx; line-height: 140rpx; color: #d91f16; font-size: 28rpx; border-top: 2rpx #ebebeb solid; border-bottom: 2rpx #ebebeb solid; padding: 0 20rpx; align-items: center; display: -webkit-flex;}

.address_top { height: 36px; line-height: 36px; background: #f5f5f5; color:rgba(153,153,153,1); font-size: 28rpx; padding: 0 20rpx;}

.address_bottom { height: 88rpx; line-height: 88rpx; background: #fff; color: #000; font-size: 28rpx; padding: 0 20rpx; border-bottom: 2rpx #ebebeb solid; margin-left: 15rpx;}

.location_img { width: 48rpx; height: 48rpx; position: absolute; right: 20rpx; top: 125rpx;}

.add_city { width: 228rpx; height: 60rpx; line-height: 60rpx; text-align: center; border: 2rpx solid #ebebeb; color: #000; margin-right: 20rpx;}

.add_citying { width: 228rpx; height: 60rpx; line-height: 60rpx; text-align: center; border: 2rpx solid #09bb07; color: #09bb07; margin-right: 20rpx;}

.orientation { white-space: normal; display: inline-block; width: 45rpx; height: 50rpx; font-size: 28rpx; font-weight: bold; color: rgb(88, 87, 87); text-align: center;}

.orientation_region { padding: 5px 0px; width: 45rpx; font-size: 20rpx; position: fixed; top: 50%; right: 6rpx; transform: translate(0, -50%); background: rgb(199, 198, 198); border-radius: 10px;}

.orientation_city { height: 40rpx; line-height: 40rpx; color: #000; text-align: center;}

.active { color: #2cc1d1;}

.list-fixed { position: absolute; width: 100%; z-index: 999; height: 36px; line-height: 36px; background: #ebebeb; color: #999; font-size: 28rpx; padding: 0 20rpx;}

.fixed-title { color: #2cc1d1;}.hide{ display: none;}


Page({

/** * 頁(yè)面的初始數(shù)據(jù) */

data: {

????isActive: null,

????listMain: [{ id: "1", region: "A", items: [{ id: "..", name: "阿明" }, { id: "..", name: "阿樂(lè)" }, { id: "..", name: "奧特曼" }, { id: "..", name: "安慶" } ] }, { id: "2", region: "B", items: [{ id: "..", name: "爸爸" }, { id: "..", name: "八仔" } ] }, { id: "3", region: "C", items: [{ id: "..", name: "車(chē)仔面" }, { id: "..", name: "吃貨" }, { id: "..", name: "蠢貨" } ] }, { id: "4", region: "D", items: [{ id: "..", name: "擔(dān)擔(dān)面" }, { id: "..", name: "刀仔" }, { id: "..", name: "兌兌" } ] }, { id: "5", region: "E", items: [{ id: "..", name: "擔(dān)擔(dān)面" }, { id: "..", name: "刀" }, { id: "..", name: "對(duì)對(duì)" } ] }, { id: "6", region: "F", items: [{ id: "..", name: "馮潔" }, { id: "..", name: "峰仔" }, { id: "..", name: "鳳姐" } ] }, ],

????fixedTitle: null,

????toView: 'inTo0',

????oHeight: [],

????scroolHeight: 0,

????fixedTop: 0 },

????//點(diǎn)擊右側(cè)字母導(dǎo)航定位觸發(fā)

????scrollToViewFn: function(e) {

????var that = this; var _id = e.target.dataset.id;

????for (var i = 0; i < that.data.listMain.length; ++i) {

????if (that.data.listMain[i].id === _id) {

????????that.setData({
?????????????isActive: _id, toView: 'inTo' + _id, fixedTitle: that.data.listMain[i].region

????????})

????????break;

}

} },?

// 頁(yè)面滑動(dòng)時(shí)觸發(fā)

onPageScroll: function(e) {

????this.setData({ scroolHeight: e.detail.scrollTop });

????for (let i in this.data.oHeight) {

????if (e.detail.scrollTop < this.data.oHeight[i].height) {

????this.setData({

????isActive: this.data.oHeight[i].key,

????fixedTitle: this.data.oHeight[i].name

????});

????return false;

} } },

// 處理數(shù)據(jù)格式鸟辅,及獲取分組高度

getBrands: function() {

????var that = this; var number = 0

//計(jì)算分組高度,wx.createSelectotQuery()獲取節(jié)點(diǎn)信息

for (let i = 0; i < that.data.listMain.length; ++i) {

????wx.createSelectorQuery().select('#inTo' + that.data.listMain[i].id).boundingClientRect(function(rect) { number = rect.height + number; var newArry = [{ 'height': number, 'key': rect.dataset.id, "name": that.data.listMain[i].region }]

????that.setData({

????oHeight: that.data.oHeight.concat(newArry)

????})

}).exec(); }; },

onLoad: function(options) {

????var that = this;

????that.getBrands();

}})

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末槐壳,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子夏哭,更是在濱河造成了極大的恐慌箕慧,老刑警劉巖服球,帶你破解...
    沈念sama閱讀 217,657評(píng)論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異销钝,居然都是意外死亡有咨,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,889評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門(mén)蒸健,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)座享,“玉大人,你說(shuō)我怎么就攤上這事似忧≡眩” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 164,057評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵盯捌,是天一觀的道長(zhǎng)淳衙。 經(jīng)常有香客問(wèn)我,道長(zhǎng)饺著,這世上最難降的妖魔是什么箫攀? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,509評(píng)論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮幼衰,結(jié)果婚禮上靴跛,老公的妹妹穿的比我還像新娘。我一直安慰自己渡嚣,他們只是感情好梢睛,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,562評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布肥印。 她就那樣靜靜地躺著,像睡著了一般绝葡。 火紅的嫁衣襯著肌膚如雪深碱。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 51,443評(píng)論 1 302
  • 那天藏畅,我揣著相機(jī)與錄音敷硅,去河邊找鬼。 笑死墓赴,一個(gè)胖子當(dāng)著我的面吹牛竞膳,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播诫硕,決...
    沈念sama閱讀 40,251評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼坦辟,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了章办?” 一聲冷哼從身側(cè)響起锉走,我...
    開(kāi)封第一講書(shū)人閱讀 39,129評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎藕届,沒(méi)想到半個(gè)月后挪蹭,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,561評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡休偶,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,779評(píng)論 3 335
  • 正文 我和宋清朗相戀三年梁厉,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片踏兜。...
    茶點(diǎn)故事閱讀 39,902評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡词顾,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出碱妆,到底是詐尸還是另有隱情肉盹,我是刑警寧澤,帶...
    沈念sama閱讀 35,621評(píng)論 5 345
  • 正文 年R本政府宣布疹尾,位于F島的核電站上忍,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏纳本。R本人自食惡果不足惜窍蓝,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,220評(píng)論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望繁成。 院中可真熱鬧吓笙,春花似錦、人聲如沸朴艰。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,838評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)祠墅。三九已至侮穿,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間毁嗦,已是汗流浹背亲茅。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,971評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留狗准,地道東北人克锣。 一個(gè)月前我還...
    沈念sama閱讀 48,025評(píng)論 2 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像腔长,于是被迫代替她去往敵國(guó)和親袭祟。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,843評(píng)論 2 354

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