当前位置: 首页 > news >正文

前端Vue 页面滑动监听 拿到滑动的坐标值

前言

前端Vue 页面滑动监听 拿到滑动的坐标值
1

实现

Vue2写法

  mounted() {// 监听页面滚动事件window.addEventListener("scroll", this.scrolling);},
methods: {
scrolling() {// 滚动条距文档顶部的距离let scrollTop =window.pageYOffset ||document.documentElement.scrollTop ||document.body.scrollTop;// 滚动条滚动的距离let scrollStep = scrollTop - this.oldScrollTop;console.log("header 滚动距离 ", scrollTop);// 更新——滚动前,滚动条距文档顶部的距离this.oldScrollTop = scrollTop;//变量windowHeight是可视区的高度let windowHeight =document.documentElement.clientHeight || document.body.clientHeight;//变量scrollHeight是滚动条的总高度let scrollHeight =document.documentElement.scrollHeight || document.body.scrollHeight;//滚动条到底部的条件if (scrollTop + windowHeight == scrollHeight) {//你想做的事情console.log("header  你已经到底部了");}if (scrollStep < 0) {console.log("header 滚动条向上滚动了!");} else {console.log("header  滚动条向下滚动了!");}// 判断是否到了最顶部if (scrollTop <= 0) {console.log("header 到了最顶部")} },},beforeDestroy() {window.removeEventListener("scroll", this.scrolling);},
http://www.lryc.cn/news/223589.html

相关文章:

  • CSS实现鼠标移至图片上显示遮罩层及文字效果
  • 【OpenCV实现图像:图像处理技巧之空间滤波】
  • 载波通讯电表的使用年限是多久?
  • 微信小程序多端应用 Donut 多端编译
  • 调试 Mahony 滤波算法的思考 10
  • Bean——IOC(Github上有代码)
  • 功能更新|Leangoo领歌免费敏捷工具支持SAFe大规模敏捷框架
  • 漏刻有时百度地图API实战开发(1)华为手机无法使用addEventListener click 的兼容解决方案
  • 交流信号继电器 DX-31BJ/AC220V JOSEF约瑟 电压启动 面板嵌入式安装
  • SpringCloudAlibaba系列之Nacos配置管理
  • Kyligence Copilot 亮相第六届进博会,增添数智新活力
  • MySQL 批量修改表的列名为小写
  • ElasticSearch 查询方法示例 java
  • 5G毫米波通信中的关键技术
  • 2.3.3 交换机的RSTP技术
  • 国外访问学者/博士后留学人员反诈骗指南
  • 设计模式之组合模式-创建层次化的对象结构
  • Windows 有趣功能集锦
  • 【nodejs版playwright】02-支持多套测试环环境执行用例
  • React高阶组件(Higher-Order Components, HOCs)
  • 利用RoboBrowser库和爬虫代理实现微博视频的爬取
  • 使用Redis实现缓存及对应问题解决
  • 【穿透科技】P2P穿透模块介绍
  • 中国第二批,11个大模型备案获批
  • 一文搞定多端开发,做全栈大牛 附三大企业实战项目
  • 带有滑动菜单指示器的纯 CSS 导航选项卡
  • Java学习笔记41——接口组成更新
  • iview实现table里面每行数据的跳转
  • Docker快速搭建Drupal内容管理系统并远程访问
  • Ansible优化大全