码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • vue2/3 tab栏切换 可左右滑动的处理


    1. <script>
    2. import { defineComponent, computed, toRefs, reactive } from 'vue'
    3. import { jsBridge } from "@/utils/jsbridge";
    4. export default defineComponent({
    5. name: 'Gooddetails',
    6. setup() {
    7. const lData = reactive({
    8. tabList: [],
    9. curTabIndx: 0
    10. })
    11. const curTab = computed(() => {
    12. return lData.tabList.find(v => v.select);
    13. })
    14. const _init = ()=> {
    15. let list = ["京东","淘宝/天猫/饿了么","美团外卖","拼多多"];
    16. list.forEach((text, idx) => {
    17. lData.tabList.push({
    18. text,
    19. id: idx, // tab标识
    20. select: idx == 0, // 是否被选择
    21. index: idx // 处于显示的位置
    22. });
    23. });
    24. }
    25. _init()
    26. const onClickTab = (tabInfo, idx) => {
    27. lData.curTabIndx = idx
    28. let curTabInfo = curTab.value;
    29. if (curTabInfo.id == tabInfo.id) return;
    30. let { index, id } = tabInfo;
    31. // 滑动控件
    32. let scroller = document.getElementById("scroller");
    33. let speed = scroller.scrollWidth / lData.tabList.length;
    34. let tab = document.getElementById(`tab-${id}`);
    35. let bWidth = document.body.clientWidth;
    36. // 点击右边
    37. if (curTabInfo.index < index && tab.clientWidth * index >= bWidth - speed) {
    38. // 滑动的距离
    39. scroller.scrollLeft = (index + 2) * speed - bWidth;
    40. } else if (curTabInfo.index > index && (tab.clientWidth * index - (scroller.scrollLeft + bWidth) < speed)) {
    41. // 滑动的距离
    42. scroller.scrollLeft = (index - 1) * speed;
    43. }
    44. curTabInfo.select = false;
    45. lData.tabList[index].select = true;
    46. }
    47. return { ...toRefs(lData), curTab, onClickTab }
    48. }
    49. })
    50. script>
    51. <style lang="scss" >
    52. @import "../../assets/styles/common.css";
    53. .lose {
    54. width: 100%;
    55. position: relative;
    56. overflow:hidden;
    57. .af{
    58. width: .48rem;
    59. height: .4rem;
    60. background-color: #f7f7f7;
    61. position: absolute;
    62. top: 0.32rem;
    63. left: 0;
    64. z-index: 2;
    65. }
    66. .tab-layout {
    67. overflow-x: scroll;
    68. display: flex;
    69. flex-wrap: nowrap;
    70. padding: .32rem 0 .28rem .48rem;
    71. position: relative;
    72. .ul:first-child{
    73. .tab-item{
    74. padding-left: 0;
    75. }
    76. }
    77. .tab-item {
    78. // min-width: 1rem;
    79. padding:0 .32rem;
    80. text-align: center;
    81. height: .4rem;
    82. font-size: .28rem;
    83. font-family: PingFangSC-Regular, PingFang SC;
    84. font-weight: 400;
    85. color: #333333;
    86. line-height: .4rem;
    87. white-space: nowrap;
    88. span.active {
    89. border-bottom:1px solid red;
    90. }
    91. }
    92. }
    93. }
    94. style>

  • 相关阅读:
    k8s自动扩缩容基于HPA
    Vue + Element ui 实现动态表单,包括新增行/删除行/动态表单验证/提交功能
    2.14 分享9个高吸睛小红书首图制作技巧,要认真学哦!【玩赚小红书】
    上市一年,市值惨跌八成!大模型救不了智云健康
    Java精进-手写持久层框架
    目标检测YOLO实战应用案例100讲-基于锐化注意力的快速目标检测算法及其在遥感场景下的应用研究(中)
    2022年11月PMP考试如何办理缓退考?攻略在这里!
    算法64-荷兰国旗问题
    NebulaGraph 的云产品交付实践
    我是如何快速从python小白达到20k?
  • 原文地址:https://blog.csdn.net/m0_62015496/article/details/128134991
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号