template里面:
<!-- tab切换star --> <ul class="tab-list" :class="{fixTitle:whether}"> <li @click="curId=0" :class="{'cur':curId===0}">产品特点</li> <li @click="curId=1" :class="{'cur':curId===1}">投保须知</li> <li @click="curId=2" :class="{'cur':curId===2}">理赔流程</li> </ul> <!-- 切换内容star -->
设置fixTitle的样式,固定在顶部,cur是当前tab点击的颜色
<div class="tab-con"> <div v-show="curId===0"> 第一部分内容 </div> <div v-show="curId===1"> 第二部分内容 </div> <div v-show="curId===2"> 第三部分内容 </div> </div>
当点击第一个产品特点的时候,对应下面的第一部分内容,点击投保须知对应第二部分内容,点击理赔流程对应第三部分内容
data里面:
data(){ return:{ whether:false, curId:0 } }
curId默认为0,展示的是产品特点的内容,也就是第一部分内容
methods里面:
设置滚动效果:
handleScroll() { var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop; // console.log(scrollTop) if(scrollTop>329){ this.whether = true; }else{ this.whether = false; } },
在mounted里面:
window.addEventListener("scroll", this.handleScroll);
补充知识:vue组件之自定义tab切换组件(吸顶、滚动定位)等效果
目标问题
进入页面后,滚动一定距离使其吸顶。滚动到某DOM可视区域后,Tab拦当前选项主动滑动到该DOM上。且点击tab拦会定位到对应的dom位置。
实现效果动图
实现目的——html结构
<template> <div class="tab__main" :style="prop.box_style "> <div class="tab__div"> <ul class="tab__list" :style="prop.attr.tab_style "> <li class="tab__item" v-for="(tabs, index) in prop.attr.tab_content" :key="tabs.tab_menu" @click="onClickTabs(index)" > <span :style="tabStyle(index)">{{ tabs.tab_menu }}</span> </li> </ul> <div class="active__line" :style="prop.attr.cur_slide_style "></div> </div> </div> </template>
实现目的——less样式
.tab__div { width: 100%; height: 102px; position: relative; padding-top: 36px; background-color: #fff; .tab__list { display: flex; .tab__item { flex: 1; font-size: 32px; } .tab__item-current { font-weight: 700; } } .active__line { position: absolute; bottom: 0; left: 0; width: 187.5px; height: 5px; background-color: #4B8FFB; transition: all 300ms; } }
实现目的——js部分
export default { name: 'TabModule', props: { prop: { type: Object } }, data () { return { scrolltop: null, dom: null, domobj: {} // 各个dom的页面位置 } }, computed: { tabStyle () { return function (params) { return this.prop.attr.tab_content[params].tab_style || '' } } }, mounted () { this.onWatchScroll() // 这里首次进入页面当前选中项为第一个 document.querySelectorAll('.tab__item')[0].style = this.prop.attr.cur_tab_style "htmlcode"><template> <div> <div class="div__header"></div> <tab-module :prop="tabattributes"></tab-module> <div :id="tabattributes.attr.tab_content[index].anchor_point" class="div__item" v-for="(item, index) in fordiv" :key="item">{{ item }}</div> <div class="div__footer">我是有底线的</div> </div> </template> import TabModule from '../../components/TabModule.vue' export default { components: { TabModule }, data () { return { tabattributes: { box_style: "margin-top: 10px;", attr: { cur_tab_style: "font-weight: 700;", cur_slide_style: "", tab_content: [{ tab_menu: "控件1", anchor_point: "DomPoint1", tab_style: "" }, { tab_menu: "控件2", anchor_point: "DomPoint2", tab_style: "" }, { tab_menu: "控件3", anchor_point: "DomPoint3", tab_style: "" }, { tab_menu: "控件4", anchor_point: "DomPoint4", tab_style: "" }] } }, fordiv: ['页面控件1', '页面控件2', '页面控件3', '页面控件4'] } } } <style lang="less" scoped> .div__header { width: 100%; height: 200px; background-color: #909; } .div__item { width: 100%; height: 400px; background-color: rgb(78, 215, 224); text-align: center; font-size: 26px; } .div__footer { width: 100%; height: 200px; background-color: #090; } </style>以上这篇vue tab滚动到一定高度,固定在顶部,点击tab切换不同的内容操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年09月21日
2024年09月21日
- [ABC]安娜-胆麦发烧女声[6N纯银镀膜][2016[低速原抓WAV+CUE]
- 任天堂今晚举行直面会!第三方及独立游戏展示
- 《哆啦A梦的铜锣烧店物语》发售!开罗公式+哆啦A梦
- 任天堂公布《塞尔达传说》系列时间线:野炊与王泪独立在外
- 五条人.2012-一些风景2CD【刀马旦】【WAV+CUE】
- 陈奕迅.2013-Easons.Life演唱会2CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 许美静.1995-遗憾(新马版)【上华】【WAV+CUE】
- 《叶倩文 歌声情缘》[WAV+CUE][410MB]
- 《张国荣 首首动听经典不容错过 追忆的风 2CD》[WAV+CUE][870MB]
- 《腾格尔 容中尔甲 亚东 高原三星 男人篇 3CD》[WAV/分轨][1GB]
- 命运圣契公测实测可用兑换码大全 命运圣契最新兑换码分享
- 黑神话悟空上品疾蝠精魄获取方法一览|上品疾蝠精魄收集攻略
- 《七龙珠电光炸裂!ZERO》GT角色预告片曝光,15位新角色登场
- [ABC]安娜-胆麦发烧女声[6N纯银镀膜][2016[低速原抓WAV+CUE]
- NewViennaOctetViennaWindSoloists-TheDeccaRecordings(2024)18CD[24-48][FLAC]-7