vue 锚点定位
vue 锚点定位
<template>
<div class="details">
<div class="wrapper w">
<div class="benefit">
<div class="benfit-left">
//这个是页签
<div class="benefit-cell" ref="searchBar" :class="{'fixed': searchBarFixed}">
<div class="benefit-cell-title tabs">
<div class="wrapper-tab">
<span class="tab" :class="{'active1':index==current}" v-for="(item,index) in nav" v-on:click="tabSelect(index)">{{item.text}}</span>
<div v-if="searchBarFixed" class="insure-btn" @click="goInsured(detailsData.code)">立即投保</div>
</div>
</div>
</div>
//第一部分
<div class="benefit-cell" ref="introduce">
<div class="benefit-cell-content">
<!--todo:产品介绍-->
<div class="wrapper" v-html="detailsData.content"></div>
</div>
</div>
//第二部分
<div class="benefit-cell" ref="problem">
<div class="benefit-cell-title">
<h4>常见问题</h4>
<a class="benefit-cell-detail" v-if="subLink.notice_more" @click="goDetails(subLink.notice_more.key,subLink.notice_more.title,detailsData.id)">{{subLink.notice_more.title}}</a>
</div>
<div class="benefit-cell-content">
<!--todo:常见问题-->
<div class="wrapper" v-html="detailsData.notice"></div>
</div>
</div>
//第三部分
<div class="benefit-cell" ref="claims">
<div class="benefit-cell-title">
<h4>理赔说明</h4>
<a class="benefit-cell-detail" v-if="subLink.claim_notice" @click="goDetails(subLink.claim_notice.key,subLink.claim_notice.title,detailsData.id)">{{subLink.claim_notice.title}}</a>
</div>
<div class="benefit-cell-content">
<!--todo:理赔内容-->
<el-steps :active="contentClaims.length" align-center style="margin:60px 0">
<el-step :title="item.title" :description="item.info" v-for="(item,index) in contentClaims" :key="index"></el-step>
</el-steps>
</div>
<div class="benefit-cell-content" style="min-height:600px">
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import urls from "@/api/urls";
let offsetTop, problemTop, claimsTop;
export default {
components: {
"bg-header": header
},
data() {
return {
detailsData: {},
productType: '',
defaultAvatar,
current: 0,
subLink: '',
insureNotes: {},
searchBarFixed: false,
nav: [{
text: '产品介绍',
target: '#introduce'
}, {
text: '常见问题',
target: '#problem'
}, {
text: '理赔说明',
target: '#claims'
}],
code:'',
contentClaims:[]
}
},
created() {
this.id = this.$route.query.id
this.getInfo()
},
mounted() {
window.addEventListener("scroll", this.handleScroll);//页面加载的时候调滚动的方法
},
methods: {
handleScroll() { //滚动的方法
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; //这里的判断是为了兼容各个浏览器
offsetTop = this.$refs.searchBar.offsetTop;
problemTop = this.$refs.problem.offsetTop;
claimsTop = this.$refs.claims.offsetTop;
if(scrollTop > offsetTop) {
this.searchBarFixed = true;
} else {
this.searchBarFixed = false;
}
if(scrollTop >= problemTop && scrollTop < claimsTop) {
this.current = 1;
} else if(scrollTop >= claimsTop) {
this.current = 2;
} else {
this.current = 0;
}
console.log(offsetTop)
},
tabSelect(index) { //tab切换的方法
this.current = index;
// 锚点实时切换
let stepTop =
this.$refs.introduce.offsetTop
let buyTop =
this.$refs.problem.offsetTop
let evaluateTop =
this.$refs.claims.offsetTop
console.log(stepTop)
switch(index) {
case 0:
if(!document.documentElement.scrollTop){ //这里的判断是为了兼容各个浏览器
document.body.scrollTop = stepTop
}else{
document.documentElement.scrollTop = stepTop
}
break
case 1:
if(!document.documentElement.scrollTop){
document.body.scrollTop = buyTop
}else{
document.documentElement.scrollTop = buyTop
}
break
case 2:
if(!document.documentElement.scrollTop){
document.body.scrollTop = evaluateTop
}else{
document.documentElement.scrollTop = evaluateTop
}
break
default:
break
}
},
}
};
</script>
<style scoped lang="less">
@import "../../assets/css/mixins";
.fixed {
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 10;
background: #fff;
box-shadow: 2px 0px 20px rgba(0, 0, 0, 0.3);
.tabs {
width: 1200px;
margin:0 auto;
}
}
</style>
vue 锚点定位的更多相关文章
- vue滑动吸顶以及锚点定位
Vue项目中需要实现滑动吸顶以及锚点定位功能.template代码如下: <template> <div class="main"> <div id= ...
- html中设置锚点定位的几种常见方法(#号定位)
在html中设置锚点定位我知道的有几种方法,在此和大家分享一下: 1.使用id定位: <a href="#1F">锚点1</a> <div id=&q ...
- 【TRICK】解决锚点定位向下浮动Xpx问题
1. 问题描述 页面滚动后,菜单栏会固定在页头,当锚点定位时,菜单会遮盖部分定位后的内容,所以需要在锚点定位后自动向下漂移Xpx. 2. 解决办法 a. 利用空div 占位,如下: <a hre ...
- 当锚点定位遇上position: fixed
<!DOCTYPE html><html> <head> <title>当锚点定位遇上position: fixed</title> < ...
- Android tabLayout+recyclerView实现锚点定位
原文链接:https://mp.weixin.qq.com/s/L3o2i3WTmg1ScXEYDS8YCg 在上一篇文章 Android 实现锚点定位中,我们介绍了tablayout+scrollV ...
- Android 实现锚点定位
相信做前端的都做过页面锚点定位的功能,通过<a href="#head"> 去设置页面内锚点定位跳转. 本篇文章就使用tablayout.scrollview来实现an ...
- 锚点定位,jquery定位到页面指定位置
jquery锚点定位 $('body,html').animate({scrollTop: $('#ter1').offset().top}, 500);#ter1是你要定位的id对象,500是0.5 ...
- js实现锚点定位
js实现锚点定位的原理是,算出定位的标签距离顶部的高度,点击触发标签,重新赋值滚动条的高度到达指定位置. <!DOCTYPE html> <html> <head> ...
- html锚点定位不准确问题
问题描述 当顶部固定时,点击锚点,会跳转到锚点以下. <style> #one,#two,#three{ height: 500px; } #top{ position: fixed; h ...
随机推荐
- Ibatis在运行期得到可执行到sql
环境:oracle-11g ,ibatis-2.0 ,java-1.7 最近因为有个需要是在程序中得到ibatis到sql字符串,即通过以下的ibatis配置得到sql语句 <select id ...
- 算法27-----第N个数字
1.题目: 在无限的整数序列 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...中找到第 n 个数字. 注意: n 是正数且在32为整形范围内 ( n < 231). ...
- mysql对事务的支持
起因:因为只是需要编写一个接口,无需使用框架,但是又要求对数据库的操作支持事务,所以直接使用mysql自带的事务进行处理 mysql自带对事务的支持,但是他默认是关闭的,需要我们手动打开,打开mysq ...
- HDU 4535 吉哥系列故事——礼尚往来( 错排水题 )
链接:传送门 思路:错排模板题,水题是非常浪费时间的. /*********************************************************************** ...
- HDU-2844 Coins 多重背包 物品数量二进制优化
题目链接:https://cn.vjudge.net/problem/HDU-2844 题意 给你一些不同价值和一定数量n的硬币. 求用这些硬币可以组合成价值在[1 , m]之间的有多少. 思路 多重 ...
- ansible 连通测试
[root@ftp:/root] > ansible ansible01 -m ping ansible01 | UNREACHABLE! => { "changed" ...
- js中的变量提升和函数提升
从上周开始,我所在的学习小组正式开始了angular的学习,angular是全面支持es6的,所以语法上和以前的angular有了很大的不同,比如变量声明时就抛弃了var,而选择了let和const: ...
- IE9以下版本兼容h5标签
随着html5(后面用h5代表)标签越来越广泛的使用,IE9以下(IE6-IE8)不识别h5标签的问题让人很是烦恼. 在火狐和chrome之类的浏览器中,遇到不认识的标签,只要给个display:bl ...
- 关于@SuppressWarnings("unchecked")注解
解释一: 屏蔽某些编译时的警告信息 在强制类型转换的时候编译器会给出警告 加上程序代码 @SuppressWarnings("unchecked& ...
- (转)Epoll模型详解
1. 内核中提高I/O性能的新方法epoll epoll是什么?按照man手册的说法:是为处理大批量句柄而作了改进的poll.要使用epoll只需要这三个系统调 用:epoll_create(2), ...