一、vue实现吸顶
场景:当页面的滚动条到一定的高度,顶部的搜索框部分和内容区右侧的瞄点部分都会定位到页面中,不会随着页面的滚动而覆盖到上面
在method方法中写:
// 监听滚动条,滚动到一定的距离,侧边栏和顶部导航就会定位
handleScroll(){
var topScroll = document.documentElement.scrollTop;
var widthClient=document.body.clientWidth;
// console.log(topScroll)
// 获取导航id
var nav = document.getElementById("search");
var dog = document.getElementById("img_dog");
var target = document.getElementById("miaodian");
// 滚动距离大于多少时执行下面事件
if (topScroll > 150) {
// console.log(ihkh)
// 到了那个距离相当于给了导航定位
this.show=false;
nav.style.position = 'fixed';
nav.style.width='100%';
nav.style.height='70px';
dog.style.width='30%';
nav.style.backgroundColor='white'