当前位置: 首页 > news >正文

滚动列表展示跟随弹框效果

需求:

现在有一个滚动列表,当我点击电话图标的时候,就会在这一行的末尾展示一个弹窗,并且可以在各个分辨率下都能动态计算它的位置,当我滚动的时候这个弹框会自动关闭

效果:

先说我在编写时候的问题,因为这个页面中是用Grid布局编写的,因此同时还有其他的模块存在:

理想状态:

实际状态:

  • 首先就是这个弹窗会被旁边的模块盖住,即使我设置了这个弹窗的z-index:200,比旁边的大,还是会。因此我在编写Grid布局的父容器,将当前这个模块的z-index设置为99(比弹窗的小就行,但要比旁边的大,根据实际情况定)。

  • 再就是滚动列表中的表头不会随着滚动,设置了粘性定位,这就导致设置绝对定位的弹窗会被粘性定位的表头盖住,所以这里需要将弹窗写在最外层容器下,而不是表格中的数据行旁边,再给弹窗设置fixed定位,并且设置pointer-events: auto; 和 overflow: visible;

下面这个结构就是我在上述说的,不要把弹窗写在list结构中,而是写在最外层和list同级中,这样就可以避免被表头盖住

<div><div class="container">弹窗</div><div class="list">列表</div>
</div>
  • 最后就是弹窗的位置是通过js获取元素去计算的,就会有一些偏移,那我们就需要+或者-一些偏移量,那如果直接写以px为单位的值,就无法做到在各个分辨率下都能适应,这里需要换算成vw或者rem

代码示例:

<template><div class="online-num-container" ref="containerRef"><div class="infinite-list-container"><div class="fixed-header"><table class="data-table header-table"><thead><tr><th style="width: 40%">姓名</th><th style="width: 40%">账号</th><th style="width: 20%"></th></tr></thead></table></div><div class="scrollable-body" ref="scrollContainer"><table class="data-table body-table"><tbody><tr v-for="(item, index) in list" :key="index"><td style="width: 40%">张三</td><td style="width: 40%">张三的账号</td><td style="width: 20%;"><imgstyle="width: 0.8vw;height: 0.8vw;cursor: pointer;"src="..."@click="(e) => togglePhoneBox(index, e)"alt=""></td></tr></tbody></table><div class="loading-status" v-if="loading"><span>加载中...</span></div><div v-if="finished && !loading"></div></div></div><divv-show="activePhoneIndex !== null && phoneBoxPosition"class="phone-box global-phone-box":style="phoneBoxPosition"ref="phoneBoxRef"><imgclass="phone-box-close"src="..."alt=""@click="activePhoneIndex = null"/><div class="phone-box-name">姓名:张三</div><div class="phone-box-phone">电话:12345678900</div></div></div>
</template>
const activePhoneIndex = ref(null)
const phoneBoxPosition = ref(null)
const phoneBoxRef = ref(null)const togglePhoneBox = async (index, event) => {if (activePhoneIndex.value === index) {activePhoneIndex.value = nullphoneBoxPosition.value = null} else {activePhoneIndex.value = indexawait nextTick()const triggerRect = event.currentTarget.getBoundingClientRect()const vw = window.innerWidth / 100const vw20 = 20 / 1920 * 100const gapPx = vw20 * vwphoneBoxPosition.value = {position: 'fixed',top: `${triggerRect.top - gapPx}px`,left: `${triggerRect.right}px`,zIndex: 200}}
}

css只给出部分代码:

父容器的:

<cur-component style="z-index: 99;" />
给当前组件设置z-index高于旁边的优先级

弹窗的:

.phone-box {width: 9vw;aspect-ratio: 28 / 9;font-size: 0.6vw;color: #eab37a;overflow: visible;
}.global-phone-box {position: fixed;z-index: 200;pointer-events: auto;
}

文章转载自:

http://D7GUaNMO.ptfsn.cn
http://Ck7482rX.ptfsn.cn
http://R30CCQx6.ptfsn.cn
http://jhVPE2hK.ptfsn.cn
http://lXILXvLw.ptfsn.cn
http://cR2vUHYZ.ptfsn.cn
http://gWIT9Jfy.ptfsn.cn
http://CeJv3Kxe.ptfsn.cn
http://ID9CyX2T.ptfsn.cn
http://3cQaBHoW.ptfsn.cn
http://rz5NBuep.ptfsn.cn
http://ldyglalA.ptfsn.cn
http://P5EzZ4TJ.ptfsn.cn
http://ypn09S3Q.ptfsn.cn
http://1Aj07APr.ptfsn.cn
http://C6WW9I96.ptfsn.cn
http://8yUHQujy.ptfsn.cn
http://BQWU7QAs.ptfsn.cn
http://w3ByGvSR.ptfsn.cn
http://Jvdyhiqs.ptfsn.cn
http://Uag01zsP.ptfsn.cn
http://bpAoRxrO.ptfsn.cn
http://JSsBJVQT.ptfsn.cn
http://VwLQZtWg.ptfsn.cn
http://tAQBOOLF.ptfsn.cn
http://4HI1eFha.ptfsn.cn
http://litjAXnG.ptfsn.cn
http://nqnsFuyo.ptfsn.cn
http://NwcXfE6g.ptfsn.cn
http://lxNAFut1.ptfsn.cn
http://www.dtcms.com/a/379077.html

相关文章:

  • readelf 和 ldd 查看文件的依赖
  • 基于社交媒体数据的公众情绪指数构建与重大事件影响分析
  • Cosign 实战:构建可信容器镜像的签名与验证体系
  • 定时器实战:LED闪烁与呼吸灯调试
  • docker部署Gitlab社区版,步骤以及外网访问出现502的解决方式
  • FairGuard aab包签名工具
  • 企业文件图纸全自动加密怎么设置?三步实现自动防护!
  • Redis C++ 实现笔记(I篇)
  • [css] 实现禁止文本被选中
  • MATLAB中进行视觉检测入门教程
  • 人工智能深度学习——多层感知器(人工神经网络)
  • 2025最新超详细FreeRTOS入门教程:第十二章 FreeRTOS调度器与时间片管理
  • 软考系统架构设计师之项目管理篇
  • OpenSTL PredRNNv2 模型复现与自定义数据集训练
  • 基于STM32的单片机开发复盘
  • Git 目录详解和基本操作(1)
  • 机器学习之K折交叉验证
  • Android Gradle Project (AGP) gradle-xxxx-src.zip无法正常下载问题解决方法
  • 图观 应用编辑器 产品介绍
  • 探讨Hyperband 等主要机器学习调优方法的机制和权衡
  • Apple产品发布会拆解:体验下放、设计极限、AI 入耳
  • 如何解决 Spring Bean 循环依赖
  • sdio NOT_AUTOGATING
  • 华为X考拉悠然 联合发布悠然智擎城市交通拥堵治理空间智能体方案
  • 《微服务事务管理》
  • CentOS 7 安装 MySQL 详细教程
  • 分布式锁解决集群下一人一单超卖问题
  • 如何解决pip安装报错ModuleNotFoundError: No module named ‘sweetviz’问题
  • @DateTimeFormat.fallbackPatterns 详解
  • 使用wavesurfer.js自定义波形绘制,集成频谱、时间轴、缩放、区域选择等插件