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 ...
随机推荐
- deploy springboot to tomcat
1 在 Eclipse 中建立新的web项目[ABC],之后 转成Maven项目. 2 创建 class Application 3 修改POM 4 修改web.xml 5 exp ...
- 『转』How to Think About Your Career
开始工作的伊始,逐渐转载及阅读Medium上知名华裔设计师Julie Zhuo的文章,这是她在medium上的介绍:Product design VP @ Facebook. Lover of foo ...
- HDU 1009 FatMouse' Trade【贪心】
解题思路:一只老鼠共有m的猫粮,给出n个房间,每一间房间可以用f[i]的猫粮换取w[i]的豆,问老鼠最多能够获得豆的数量 sum 即每一间房间的豆的单价为v[i]=f[i]/w[i],要想买到最多的豆 ...
- UVA340-Master-Mind Hints(紫书例题3.4)
MasterMind is a game for two players. One of them, Designer, selects a secret code. The other, Break ...
- selenium chrome.options禁止加载图片和js
#新建一个选项卡 from selenium import webdriver options = webdriver.ChromeOptions() #禁止加载图片 prefs = { 'profi ...
- WinServer-IIS-压缩及缓存
静态内容压缩: 默认10s内有2个客户端一起请求服务器的话,服务器就会把相关的静态内容压缩返回 动态内容压缩: 默认IIS的程序域最高可以占用CPU90%的资源,这个可以通过命令行修改 缓存和内核缓存 ...
- Linux内核源码情景分析-wait()、schedule()
父进程执行wait4,并调用schedule切换到子进程: wait4(child, NULL, 0, NULL); 像其它系统调用一样.wait4()在内核中的入口是sys_wait4().代码例如 ...
- MySQL 创建表时,设置时间字段自己主动插入当前时间
MySQL 创建表时,设置时间字段自己主动插入当前时间 DROP TABLE IF EXISTS `CONTENT`; CREATE TABLE `CONTENT` ( `ID` char(20) N ...
- hello world to php( mac 配置 xmapp virtual host)
一.安装xmapp.安装完以后查看,服务是否都能启动(数据库和server) 二.配置自己的virtualhost 1.系统host文件加入server的域名(在浏览器中输入域名后会先通过 ...
- C++中对字符串进行插入、替换、删除操作
#include <iostream> #include <string> using std::cout; using std::endl; using std::strin ...