当前位置:网站首页>直播商城源码,实现左右联动商品分类页面
直播商城源码,实现左右联动商品分类页面
2022-07-01 00:42:00 【云豹网络科技】
直播商城源码,实现左右联动商品分类页面
一、搭建结构
重点:使用uniapp的scroll-view组件,如果是小程序原生开发也是这个组件;其次如果是html开发,就自己实现一个溢出滚动。
废话不多说,上代码:
<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;">加载失败</text></view>
<view class="item-menu-name">{
{
item1.name}}</view>
</view>
</view>
</view>
</view>
</scroll-view>
</view>
</view>
</template>
JavaScript业务逻辑代码:
data() {
return {
scrollTop: 0, //tab标题的滚动条位置
oldScrollTop: 0, // tab标题的滚动条旧位置
current: 0, // 预设当前项的值
menuHeight: 0, // 左边菜单的高度
menuItemHeight: 0, // 左边菜单item的高度
itemId: '', // 栏目右边scroll-view用于滚动的id
tabbar: JSON.parse(uni.getStorageSync('categroy')), // 渲染的数据,放在最后供你们测试
arr: [], // 储存距离顶部高度的数组
scrollRightTop: 0, // 右边栏目scroll-view的滚动条高度
timer: null // 定时器
}
}
二、添加逻辑层业务
分别获取左侧和右侧每一个类别的高度
我们知道,在uniapp里面没有window对象和dom元素,所以如果我们要获取页面上的一些节点信息时,需要通过uni.createSelectorQuery()这个API来获取,这里不再赘述。—— 《传送地址》
/** * 获取一个目标元素的高度 * @elClass 元素的类名 * @dataVal 储存高度的对象 */
methods: {
getElRect(elClass, dataVal) {
new Promise((resolve, reject) => {
const query = uni.createSelectorQuery().in(this);
query.select('.' + elClass).fields({
size: true
}, res => {
// 如果节点尚未生成,res值为null,循环调用执行
if (!res) {
setTimeout(() => {
this.getElRect(elClass);
}, 10);
return;
}
this[dataVal] = res.height;
resolve();
}).exec();
})
}
}
计算右侧每个分类距离顶部的高度并保存
onReady() {
this.getMenuItemTop()
},
mehods: {
/** * 获取右边菜单每个item到顶部的距离 * 储存到 arr 数组里面用于后面滚动判断 */
getMenuItemTop() {
new Promise(resolve => {
let selectorQuery = uni.createSelectorQuery();
selectorQuery.selectAll('.class-item').boundingClientRect((rects) => {
// 如果节点尚未生成,rects值为[](因为用selectAll,所以返回的是数组),循环调用执行
if(!rects.length) {
setTimeout(() => {
this.getMenuItemTop();
}, 10);
return ;
}
rects.forEach((rect) => {
// 视情况而定,这里减去rects[0].top,是因为第一项顶部可能不是贴到导航栏(比如有个搜索框的情况)
// this.arr.push(rect.top - rects[0].top);
this.arr.push(rect.top)
resolve();
})
}).exec()
})
},
}
以上就是直播商城源码,实现左右联动商品分类页面, 更多内容欢迎关注之后的文章
边栏推荐
- 系统设置大页
- MFC TCP communication server client demo notes vs2019
- Call the classic architecture and build the model based on the classic
- K210 site helmet
- StrictMode带来的思考-StrictMode原理(5)
- mysql数据库基础:流程控制
- 图的连通性基础
- StrictMode卡顿与泄漏检测-StrictMode原理(2)
- Docker deployment MySQL 8
- Service grid ASM year end summary: how do end users use the service grid?
猜你喜欢

用recyclerReview展示Banner,很简单

Call the classic architecture and build the model based on the classic

Poor students can also play raspberry pie

流批一体在京东的探索与实践

Interpreting the scientific and technological literacy contained in maker Education

neo4j安装、运行以及项目的构建和功能实现

基础知识之二——STA相关的基本定义

6月第4周榜单丨飞瓜数据UP主成长排行榜(哔哩哔哩平台)发布!

Dls-42/6-4 dc110v double position relay

qt5-MVC:数据可视化的层次揭秘
随机推荐
js中把数字转换成汉字输出
None of the following candidates is applicable because of a receiver type mismatch
Introduction and principle analysis of cluster and LVS
gin_gorm
1175. Prime Arrangements
【网络丢包,网络延迟?这款神器帮你搞定所有!】
WIN11中MathType编辑中“打开数学输入面板”是灰色不可编辑
Exploring the road of steam education innovation in the Internet Era
孙宇晨接受瑞士媒体Bilan采访:熊市不会持续太久
Thinking brought by strictmode -strictmode principle (5)
Analyze the maker education path integrating the essence of discipline
面对产业互联网的时候,甚至还用消费互联网的方式和方法去落地和实践产业互联网
做生意更加务实
Matlab farthest point sampling (FPS improved version)
Docker deployment MySQL 8
C语言一点点(未来可会增加)
【队列】933. Number of Recent Calls
MATLAB 最远点采样(FPS改进版)
Pre training / transfer learning of models
Relationship between ASCII, Unicode, GBK, UTF-8