当前位置:网站首页>Live shopping mall source code, realize left-right linkage of commodity classification pages
Live shopping mall source code, realize left-right linkage of commodity classification pages
2022-07-01 01:49:00 【Yunbao network technology】
Live mall source code , Realize the left-right linkage commodity classification page
One 、 Build structure
a key : Use uniapp Of scroll-view Components , If it is a small program, the native development is also this component ; Second, if it's html Development , Just implement an overflow scroll .
I don't say much nonsense , Code up :
<template>
<view class="u-wrap">
<view class="u-menu-wrap">
<scroll-view scroll-y scroll-with-animation class="u-tab-view menu-scroll-view" :scroll-top="scrollTop"
:scroll-into-view="itemId">
<view v-for="(item,index) in tabbar" :key="index" class="u-tab-item" :class="[current == index ? 'u-tab-item-active' : '']"
@tap.stop="swichMenu(index)">
<text class="u-line-1">{
{
item.name}}</text>
</view>
</scroll-view>
<scroll-view :scroll-top="scrollRightTop" scroll-y scroll-with-animation class="right-box" @scroll="rightScroll">
<view class="page-view">
<view class="class-item" :id="'item' + index" v-for="(item , index) in tabbar" :key="index">
<view class="item-title">
<text>{
{
item.name}}</text>
</view>
<view class="item-container">
<view class="thumb-box" v-for="(item1, index1) in item.foods" :key="index1" @click="featureC(item1.cat, item1.name)">
<image v-if="item1.icon != ''" class="item-menu-image" :src="item1.icon" mode=""></image>
<view v-else class="item-menu-image row-c" style="background-color: #F4F6F8;"><text style="font-size: 20rpx;color: #d0d0d0;"> Loading failed </text></view>
<view class="item-menu-name">{
{
item1.name}}</view>
</view>
</view>
</view>
</view>
</scroll-view>
</view>
</view>
</template>
JavaScript Business logic code :
data() {
return {
scrollTop: 0, //tab The scroll bar position of the title
oldScrollTop: 0, // tab The old position of the scroll bar of the title
current: 0, // Default the value of the current item
menuHeight: 0, // The height of the menu on the left
menuItemHeight: 0, // Left menu item Height
itemId: '', // On the right side of the column scroll-view For scrolling id
tabbar: JSON.parse(uni.getStorageSync('categroy')), // Rendered data , Put it at the end for you to test
arr: [], // Store an array of heights from the top
scrollRightTop: 0, // The right column scroll-view Scroll bar height
timer: null // Timer
}
}
Two 、 Add logical layer business
Get the height of each category on the left and right respectively
We know , stay uniapp There's no window Objects and dom Elements , So if we want to get some node information on the page , Need to pass through uni.createSelectorQuery() This API To get , No more details here .—— 《 Delivery address 》
/** * Get the height of a target element * @elClass The class name of the element * @dataVal Store height objects */
methods: {
getElRect(elClass, dataVal) {
new Promise((resolve, reject) => {
const query = uni.createSelectorQuery().in(this);
query.select('.' + elClass).fields({
size: true
}, res => {
// If the node has not been generated ,res The value is null, Loop call execution
if (!res) {
setTimeout(() => {
this.getElRect(elClass);
}, 10);
return;
}
this[dataVal] = res.height;
resolve();
}).exec();
})
}
}
Calculate the height of each category on the right from the top and save
onReady() {
this.getMenuItemTop()
},
mehods: {
/** * Get each menu on the right item The distance to the top * Store in arr The array is used for later scrolling judgment */
getMenuItemTop() {
new Promise(resolve => {
let selectorQuery = uni.createSelectorQuery();
selectorQuery.selectAll('.class-item').boundingClientRect((rects) => {
// If the node has not been generated ,rects The value is []( Because with selectAll, So the return is an array ), Loop call execution
if(!rects.length) {
setTimeout(() => {
this.getMenuItemTop();
}, 10);
return ;
}
rects.forEach((rect) => {
// As the case may be , Subtract... Here rects[0].top, Because the top of the first item may not be attached to the navigation bar ( For example, there is a search box )
// this.arr.push(rect.top - rects[0].top);
this.arr.push(rect.top)
resolve();
})
}).exec()
})
},
}
The above is the source code of the live broadcast Mall , Realize the left-right linkage commodity classification page , More content welcome to follow the article
边栏推荐
- [fundamentals of wireless communication-15]: illustrated mobile communication technology and application development-3-overview of digital communication 2G GSM, CDMA, 3G wdcma/cdma200/td-scdma, 4G LTE
- QT web development - VIDEO - Notes
- [Agora] user management
- Sitge joined the opengauss open source community to jointly promote the ecological development of the database industry
- 数学知识:求组合数 III—求组合数
- Batch import of Excel data in applet
- 软件开发中的上游和下游
- [Qt5 tab] tab label and content hierarchical analysis
- 聚焦绿色低碳,数据中心散热进入“智能冷却”新时代
- 直播商城源码,实现左右联动商品分类页面
猜你喜欢
随机推荐
Lecun, a Turing Award winner, pointed out that the future of AI lies in self-learning, and the company has embarked on the journey
PHP converts two-dimensional array elements into key value pairs
数据探索电商平台用户行为流失分析
静态域与静态方法
TypeError: Argument ‘angle‘ can not be treated as a double
思特奇加入openGauss开源社区,共同推动数据库产业生态发展
What will Web3 bring in the future?
CorelDRAW 2022中文精简64位直装版下载
7-2 punch in reward DP for puzzle a
模板:全局平衡二叉树
Test essential tool - postman practical tutorial
gin_ gorm
Mathematical knowledge: finding combinatorial number III - finding combinatorial number
There is no future to be expected. It is just the last fantasy of a migrant worker before he dies
[problem handled] -nvidia SMI command cannot obtain the GPU process number of its own container and the external GPU process number
The whole process of AS400 API from zero to one
Open3d point cloud bounding box
(翻译)实时内联验证更容易让用户犯错的原因
Microbiological health, why is food microbiological testing important
测试必备工具-Postman实战教程









