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


直接上代碼:
wxml界面:
<view class='header'>
<text class='headerClass'>分類</text>
<text class='headerPin'>/品牌</text>
<view class="search">
<image src='/images/搜索.png'></image>
<text>搜索商品</text>
</view>
</view>
<view class='main'>
<view class='left'>
<scroll-view scroll-y="true" style="height: 1100rpx" scroll-into-view="true" scroll-with-animation="true">
<block wx:for="{{leftText}}" wx:for-list="item">
<view class="{{classfiySelect == item.id?'active':''}}" data-id='{{item.id}}' bindtap='left_list'>
<text>{{item.text1}}</text>
</view>
</block>
</scroll-view>
</view>
<view class='right'>
<scroll-view scroll-y="true" style="height: 1100rpx" bindscroll="scroll" scroll-top="{{scrollTop}}" scroll-into-view="{{'inToview'+rigId}}" scroll-with-animation="true">
<block wx:for="{{rightData}}" wx:for-list="item">
<view class='itemTitle' id="{{'inToview'+item.id}}">{{item.title}}</view>
<view bindtap='particulars' class='listItem' data-id='{{item.id}}'>
<block wx:for="{{item.frist}}">
<view class='listItem2' data-text="{{}}">
<view class='img'>
<image src='{{item.url}}'></image>
</view>
<view class='listText'>
<text>{{item.text}}</text>
<text class='money'>¥{{item.money}}</text>
<view>
<text>已售{{item.sum}}</text>
<button size='mini' bindtap='particulars'>立即搶購(gòu)</button>
</view>
</view>
</view>
</block>
</view>
</block>
</scroll-view>
</view>
</view>
js界面:
// pages/class/class.js
Page({
/**
* 頁(yè)面的初始數(shù)據(jù)
*/
data: {
classfiySelect: "",
leftText: [{
id: "01",
text1: "美妝專區(qū)",
},
{
id: "02",
text1: "面部清潔",
},
{
id: "03",
text1: "洗護(hù)專區(qū)",
},
{
id: "04",
text1: "面膜",
},
{
id: "05",
text1: "口紅",
},
{
id: "06",
text1: "美妝專區(qū)",
},
{
id: "07",
text1: "面部清潔",
},
{
id: "08",
text1: "洗護(hù)專區(qū)",
},
{
id: "09",
text1: "面膜",
},
{
id: "010",
text1: "口紅",
},
{
id: "011",
text1: "美妝專區(qū)",
},
{
id: "012",
text1: "面部清潔",
},
{
id: "013",
text1: "洗護(hù)專區(qū)",
},
{
id: "014",
text1: "面膜",
},
{
id: "015",
text1: "口紅",
},
{
text1: "美妝專區(qū)",
},
{
text1: "面部清潔",
},
{
text1: "洗護(hù)專區(qū)",
},
{
text1: "面膜",
},
{
text1: "口紅",
},
],
rightData: [{
id: "01",
title: "美妝專區(qū)",
frist: [{
url: "/images/85309.jpg",
text: "卡姿蘭補(bǔ)水套裝",
money: 200,
sum: 20,
id:1,
},
{
url: "/images/85309.jpg",
text: "卡姿蘭補(bǔ)水套裝",
money: 200,
sum: 20,
id: 2,
},
{
url: "/images/85309.jpg",
text: "卡姿蘭補(bǔ)水套裝",
money: 200,
sum: 20,
},
],
},
{
id: "02",
title: "面部清潔",
frist: [{
url: "/images/85309.jpg",
text: "卡姿蘭補(bǔ)水套裝",
money: 200,
sum: 20,
},
{
url: "/images/85309.jpg",
text: "卡姿蘭補(bǔ)水套裝",
money: 200,
sum: 20,
},
{
url: "/images/85309.jpg",
text: "卡姿蘭補(bǔ)水套裝",
money: 200,
sum: 20,
},
],
},
{
id: "03",
title: "洗護(hù)專區(qū)",
frist: [{
url: "/images/85309.jpg",
text: "卡姿蘭補(bǔ)水套裝",
money: 200,
sum: 20,
},
{
url: "/images/85309.jpg",
text: "卡姿蘭補(bǔ)水套裝",
money: 200,
sum: 20,
},
{
url: "/images/85309.jpg",
text: "卡姿蘭補(bǔ)水套裝",
money: 200,
sum: 20,
},
],
},
{
id: "04",
title: "面膜",
frist: [{
url: "/images/85309.jpg",
text: "卡姿蘭補(bǔ)水套裝",
money: 200,
sum: 20,
},
{
url: "/images/85309.jpg",
text: "卡姿蘭補(bǔ)水套裝",
money: 200,
sum: 20,
},
{
url: "/images/85309.jpg",
text: "卡姿蘭補(bǔ)水套裝",
money: 200,
sum: 20,
},
],
},
{
id: "05",
title: "口紅",
frist: [{
url: "/images/85309.jpg",
text: "卡姿蘭補(bǔ)水套裝",
money: 200,
sum: 20,
},
{
url: "/images/85309.jpg",
text: "卡姿蘭補(bǔ)水套裝",
money: 200,
sum: 20,
},
{
url: "/images/85309.jpg",
text: "卡姿蘭補(bǔ)水套裝",
money: 200,
sum: 20,
},
],
},
{
id: "06",
title: "美妝專區(qū)",
frist: [{
url: "/images/85309.jpg",
text: "卡姿蘭補(bǔ)水套裝",
money: 200,
sum: 20,
},
{
url: "/images/85309.jpg",
text: "卡姿蘭補(bǔ)水套裝",
money: 200,
sum: 20,
},
{
url: "/images/85309.jpg",
text: "卡姿蘭補(bǔ)水套裝",
money: 200,
sum: 20,
},
],
},
],
},
/**
* 生命周期函數(shù)--監(jiān)聽頁(yè)面加載
*/
onLoad: function(options) {
this.setData({
classfiySelect: this.data.leftText[0].id
})
},
/**
* 生命周期函數(shù)--監(jiān)聽頁(yè)面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁(yè)面顯示
*/
onShow: function() {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁(yè)面隱藏
*/
onHide: function() {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁(yè)面卸載
*/
onUnload: function() {
},
/**
* 頁(yè)面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動(dòng)作
*/
onPullDownRefresh: function() {
},
/**
* 頁(yè)面上拉觸底事件的處理函數(shù)
*/
onReachBottom: function() {
},
/**
* 用戶點(diǎn)擊右上角分享
*/
onShareAppMessage: function() {
},
//滾動(dòng)觸發(fā)
scroll: function(e) {
var scrollTop = e.detail.scrollTop,
h = 0,
classfiySelect;
var that = this;
that.data.leftText.forEach(function(clssfiy, i) {
var _h =26 + that.length(clssfiy['id'])*102;
if (scrollTop >= h){
classfiySelect = clssfiy['id'];
}
h +=_h;
console.log(h);
})
that.setData({
classfiySelect: classfiySelect,
})
},
//求每一欄高度
length: function(e) {
var that = this;
var rightData = that.data.rightData;
for (var i = 0; i < rightData.length; i++) {
if(rightData[i]['id']==e){
return rightData[i]['frist'].length;
}
}
},
//點(diǎn)擊左邊事件
left_list: function(e) {
var that = this;
var l_id = e.currentTarget.dataset.id;
that.setData({
rigId: l_id,
})
},
//跳轉(zhuǎn)詳情界面
particulars:function(e){
}
})
wxss界面:
.header{
display: flex;
background-color: rgba(219, 219, 221, 0.884);
align-items: center;
height: 60rpx;
}
.active{
color: red;
}
.header .headerClass{
color: red;
margin-left: 20rpx;
}
.header .headerClass,
.header .headerPin{
font-size: 28rpx;
}
.search{
display: flex;
height: 46rpx;
border-radius: 20rpx;
margin-left: 30rpx;
background-color:white;
width: 70%;
}
.search text{
color: gainsboro;
font-family: monospace;
font-size: 30rpx;
line-height: 46rpx;
}
.search image{
padding-left:50rpx;
width: 46rpx;
height: 46rpx;
}
.main{
display: flex;
}
.left{
width: 25%
}
.left view{
padding-top: 30rpx;
text-align: center;
}
.right{
width: 75%;
}
.listItem2{
display: flex;
}
.listItem .img{
width: 200rpx;
height: 200rpx;
text-align: center;
padding-top: 10rpx;
}
.listItem .img image{
width: 80%;
height: 80%
}
.itemTitle{
font-size: 32rpx;
padding-left: 20rpx;
padding-top: 10rpx;
color:gray;
}
.listItem .listText{
display: flex;
flex-direction: column;
margin-top: 6rpx;
}
.listItem .listText view{
display: flex;
align-items: flex-end;
}
.listItem .listText text{
font-size: 34rpx;
margin-top: 10rpx;
}
.listItem .listText .money{
color: red;
}
.listItem .listText view text{
font-size: 28rpx;
color :silver;
margin-right: 60rpx;
}
.listItem .listText view button{
background-color: red;
color: white;
padding-right: 8px;
padding-left: 8px;
padding-top: 0px;
}
::-webkit-scrollbar
{
width: 6px;
height: 6px;
background-color: #ffffff;
}
::-webkit-scrollbar-track{
height: 20rpx;
color: black;
}
為大家推薦現(xiàn)在關(guān)注度比較高的微信小程序教程一篇:《微信小程序開發(fā)教程》小編為大家精心整理的,希望喜歡。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序?qū)崿F(xiàn)聯(lián)動(dòng)菜單
- 微信小程序?qū)崿F(xiàn)菜單左右聯(lián)動(dòng)
- 微信小程序scroll-view實(shí)現(xiàn)左右聯(lián)動(dòng)效果
- 微信小程序?qū)崿F(xiàn)左右聯(lián)動(dòng)
- 微信小程序scroll-view實(shí)現(xiàn)左右聯(lián)動(dòng)
- 微信小程序?qū)崿F(xiàn)購(gòu)物頁(yè)面左右聯(lián)動(dòng)
- 微信小程序?qū)崿F(xiàn)左右聯(lián)動(dòng)的實(shí)戰(zhàn)記錄
- 微信小程序?qū)崿F(xiàn)菜單左右聯(lián)動(dòng)效果
相關(guān)文章
HTML+CSS+JS實(shí)現(xiàn)完美兼容各大瀏覽器的TABLE固定列
本文給大家分享的是使用HTML+CSS+JS實(shí)現(xiàn)完美兼容各大瀏覽器的TABLE固定列的方法和示例,非常的實(shí)用,特別是在BS架構(gòu)的企業(yè)級(jí)應(yīng)用,有需要的小伙伴可以參考下。2015-04-04
js刪除數(shù)組中的元素delete和splice的區(qū)別詳解
下面小編就為大家分享一篇js刪除數(shù)組中的元素delete和splice的區(qū)別詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-02-02
JavaScript 中實(shí)現(xiàn) use strict的方法及優(yōu)勢(shì)
本教程將討論JavaScript中的use strict特性,在這里,我們將通過(guò)不同的示例了解如何在JavaScript代碼語(yǔ)句中創(chuàng)建和執(zhí)行use strict關(guān)鍵字,需要的朋友可以參考下2023-09-09
親自教你TypeScript 項(xiàng)目搭建過(guò)程
這篇文章主要介紹了親自教你TypeScript 項(xiàng)目搭建過(guò)程,我記得前一天,我們配置過(guò)一份 webpack 配置,直接復(fù)制過(guò)來(lái)使用,這里就不多說(shuō)了,然后就是在項(xiàng)目中引入我們的 less,需要的朋友可以參考下2022-11-11
JavaScript 如何刪除小數(shù)點(diǎn)后的數(shù)字
這篇文章主要介紹了JavaScript 刪除小數(shù)點(diǎn)后的數(shù)字實(shí)例代碼,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-07-07
Web打印解決方案之證件套打的實(shí)現(xiàn)思路
這篇文章主要介紹了Web打印解決方案之證件套打的實(shí)現(xiàn)思路的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-08-08
簡(jiǎn)單談?wù)凧avaScript寄生式組合繼承
寄生組合式繼承,是集寄生式繼承和組合繼承的有點(diǎn)與一身,主要是通過(guò)借用構(gòu)造函數(shù)來(lái)繼承屬性,通過(guò)原型鏈的混成形式來(lái)繼承方法,這篇文章主要給大家介紹了關(guān)于JavaScript寄生式組合繼承的相關(guān)資料,需要的朋友可以參考下2021-08-08
JS實(shí)現(xiàn)數(shù)組去重方法總結(jié)(六種方法)
這篇文章給大家總結(jié)下JS實(shí)現(xiàn)數(shù)組去重方法(六種方法),面試中也經(jīng)常會(huì)遇到這個(gè)問(wèn)題。文中給大家引申的還有合并數(shù)組并去重的方法,感興趣的朋友跟隨腳本之家小編一起學(xué)習(xí)吧2017-07-07

