原生js判断某个区域的滚动条滚动到了底部
原生js判断某个区域的滚动条滚动到了底部###
讲解==》
关系公式:element.scrollHeight - element.scrollTop === element.clientHeight
解释:此公式可以用于判断是否滚动到底
你必须知道这个方法 可以判断滚动条滚动到了底部哈!
element.scrollHeight 是获取这个元素区域的实际高度(包含被隐藏起来的高度)
element.scrollTop是获取滚动条距离顶部的实际距离(包含被隐藏起来的高度)
element.clientHeight: 就是元素内部(可见高度) + 自身padding
在生命周期函数中 给滚动区域的元素注册滚动事件
element.addEventListener('scroll', this.doSomething);
<div id="app">
<div class="box" id="box">
<div class="demo" v-for="(item,index) in condata" :key="index">{{item}}</div>
</div>
</div>
<!-- import Vue before Element -->
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/element-ui@2.4.11/lib/index.js"></script>
<script>
new Vue({
el: '#app',
data() {
return {
condata:["121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212","121212",
"121212","121212","121212","121212","121212","121212","121212","121212","最后一条数据了",
],
boxScrollpositionHeight:0,
boxElement:"",
boxscrollPosition:0,//滚动条所在的高度()
}
},
mounted () {
this.boxElement=document.getElementById("box");
this.boxElement.addEventListener('scroll', this.doSomething);
// 获取滚动条滚动区域盒子的高度
this.boxScrollpositionHeight=this.boxElement.offsetHeight;
console.log("div内容区域的实际高度",this.boxElement.scrollHeight)
},
methods: {
doSomething(){
//此时滚动条所在的高度
let scrollcurHeight=this.boxElement.scrollTop;
console.log("滚动条距离顶部的实际高度",this.boxElement.scrollTop)
console.log("hah",this.boxElement.clientHeight)
// 关系公式:element.scrollHeight - element.scrollTop === element.clientHeight
// 解释:此公式可以用于判断是否滚动到底
if(this.boxElement.scrollHeight-this.boxElement.scrollTop===this.boxElement.clientHeight){
console.log("滚动到底部了",)
}
}
},
beforeDestroy() {
let boxscrollPosition=document.getElementById("box");
boxscrollPosition.removeEventListener('scroll', this.doSomething);
},
})
</script>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
body,html,#app{
height: 100%;
}
.box{
width: 300px;
height: calc(100% - 279px);
background: #0366D6;
overflow: hidden;
overflow-y: auto;
}
.demo{
height: 30px;
line-height: 30px;
border-top:1px solid #ccc;
}
</style>
原生js判断某个区域的滚动条滚动到了底部的更多相关文章
- JS判断页面是否出现滚动条
今天无聊,帮一个网友解决一个很无聊的问题,用JS判断页面是否出现滚动条,在网上看了一些代码,经过验证并不起作用,下面是在网上搜索到的代码: 当可视区域小于页面的实际高度时,判定为出现滚动条,即: if ...
- 原生js判断css动画结束 css 动画结束的回调函数
原文:原生js判断css动画结束 css 动画结束的回调函数 css3 的时代,css3--动画 一切皆有可能: 传统的js 可以通过回调函数判断动画是否结束:即使是采用CSS技术生成动画效果,Jav ...
- JS 判断鼠标滚轮的上下滚动
JS 判断鼠标滚轮的上下滚动 <script type="text/javascript"> var scrollFunc = function (e) { e = ...
- 当滚动条滚动到页面底部自动加载增加内容的js代码
这篇文章主要介绍了如何使用javscript实现滚动条滚动到页面底部自动加载增加页面内容,需要的朋友可以参考下..1,注册页面滚动事件,window.onscroll = function(){ }; ...
- js 判断一个元素是否在滚动的可视区域内,不在就固定到可视区域的上方。
前言:最近工作中,有这样一个场景,判断一个元素是否在滚动的可视区域内,不在就固定到可视区域的上方.为了以后再次遇到,所以记录下来,并分享.转载请注明出处:https://www.cnblogs.com ...
- 判断滚动条滚动到document底部
滚动条没有实际的高度.只是为了呈现效果才在外型上面有长度. 在js当中也没有提供滚动条的高度API. 参考了网上有关资料:判断滚动条到底部的基本逻辑是滚动条滚动的高度加上视口的高度,正好是docume ...
- 原生js判断css3动画过度(transition)结束 transitionend事件 以及关键帧keyframes动画结束(animation)回调函数 animationEnd 以及 css 过渡 transition无效
上图的 demo 主要讲的 是 css transition的过渡回调函数transitionend事件: css3 的时代,css3--动画 一切皆有可能: 传统的js 可以通过回调函数判断动画 ...
- 通过 JS 判断页面是否有滚动条的简单方法
前言 最近在写插件的过程中,需要使用 JS 判断是否有滚动条,搜了一下,大致方法都差不多,但都有些啰嗦,代码不够简洁.最终通过参考不同方法,写了一个比较简单的方法.在判断滚动条的同时也需要计算滚动条的 ...
- 无间歇文字滚动_ 原生js实现新闻无间歇性上下滚动
这篇文章主要介绍使用js实现文字无间歇性上下滚动,一些网站的公告,新闻列表使用的比较多,感兴趣的小伙伴们可以参考一下 ,代码实现如下. html+css部分: <style> #moocb ...
- 原生JS判断密码强弱
前些天工作中有这个需求,自己手写了相关的JS代码,第一种方法是通过ASCII 码判断密码类型,完成用户注册时判断用户输入密码的强度,分强.弱.中三等级,它可以根据用户输入的密码显示对应的密码强弱等级, ...
随机推荐
- 云图说丨应用宕机怎么办?MAS帮您实现业务无缝切换
摘要: 多云高可用服务(Multi-cloud high Availability Service,简称MAS)源自华为消费者多云应用高可用方案,提供从流量入口.数据到应用层的端到端的业务故障切换及容 ...
- 顶级加密混淆混淆工具测评:ipagurd
顶级加密混淆混淆工具测评:ipagurd 摘要 JavaScript代码安全需求日益增长,因此JavaScript混淆工具的使用变得广泛.本文将对专业.商业JavaScript混淆工具ipagur ...
- Solon2 开发之插件,四、插件热插拔管理机制(H-Spi)
插件热插拔管理机制,简称:H-Spi.是框架提供的生产时用的另一种高级扩展方案.相对E-Spi,H-Spi 更侧重隔离.热插热拔.及管理性. 应用时,是以一个业务模块为单位进行开发,且封装为一个独立插 ...
- 如何删除PPT中工具栏口袋动画
口袋动画官网无法打开 http://www.papocket.com/ 插件无法使用 卸载 在[程序和功能]中卸载后,打开PPT,菜单还是存在 选项--加载项,点击以p开头的一串代码(com加载项), ...
- 鸿蒙HarmonyOS实战-ArkTS语言(基本语法)
一.ArkTS语言基本语法 1.简介 HarmonyOS的ArkTS语言是一种基于TypeScript开发的语言,它专为HarmonyOS系统开发而设计.ArkTS语言结合了JavaScript的灵活 ...
- 这两种完全不同的JPEG加载方式,你肯定见过!
现如今网站所使用的的图片格式多种多样,但是有一种图片格式占到了 74% 的使用量.它就是 JPEG,即联合图像专家组.这类文件的后缀通常为 .jpg 或 .jpeg,是摄影中常见的图片类型. JPEG ...
- POJ - 1611 : The Suspects (普通并查集)
思路: 模板题,一步一步加入集合,最后判断有多少人跟0在同一个集合就行了. #include<iostream> #include<cstdio> using namespac ...
- 2018年第九届 蓝桥杯A组 C/C++决赛题解
蓝桥杯历年国赛真题汇总:Here 1.三角形面积 已知三角形三个顶点在直角坐标系下的坐标分别为: (2.3, 2.5) (6.4, 3.1) (5.1, 7.2) 求该三角形的面积. 注意,要提交的是 ...
- kafka搭建 一、单机版
系列导航 一.kafka搭建-单机版 二.kafka搭建-集群搭建 三.kafka集群增加密码验证 四.kafka集群权限增加ACL 五.kafka集群__consumer_offsets副本数修改 ...
- <vue 基础知识 5、事件监听>
代码结构 一. v-on基本使用 1.效果 按钮点击一下数字增加1 2.代码 01-v-on基本使用.html <!DOCTYPE html> <html lang=&quo ...