当前位置:网站首页>JS judge the element to the top and fix it
JS judge the element to the top and fix it
2022-04-22 08:33:00 【Nanqiao Jixu】
Catalog
JS in offsetTop、clientTop、scrollTop Introduction of each attribute
JQuery
When the page scrolls 290 After pixels class by userCentLeft Element suspension
$(document).scroll(function () {
// Scroll to the top hide
$(window).scroll(function () {
let top = $(window).scrollTop()// Window scrolling distance
if (top >= 290) {
$('.userCentLeft').addClass('fixed-card')
} else {
$('.userCentLeft').removeClass('fixed-card')
}
})
}
JS
window.onscroll = function () {
// To ensure compatibility , Take two values here , Which has value, which one
//scrollTop Is the height of the roller when the roller event is triggered
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
};
scrollTop
js obtain document node
document Of getElementById('id') Method
document Of getElementByClassName('class') Method
document Of getElementsByTagName('tag') Method
document Of getElementByName('name') Method
JS in offsetTop、clientTop、scrollTop Introduction of each attribute
Here is Javascript Common properties for making scrolling code in
1.offsetTop
The distance from the current object to the top of its superior layer .
2.offsetLeft
The distance from the current object to the left of its superior layer .
3.offsetWidth
The width of the current object .( Including the width of the sideline )
And style.width The difference between attributes is :
1) For example, the width setting value of the object is percentage width , Whether the page becomes larger or smaller ,style.width All return this percentage .
2) and offsetWidth Returns the width value of the object in different pages instead of the percentage value
4.offsetHeight
The height of the current object .( Height including edge line )
1) And style.height The difference between attributes is : For example, the width of the object is set to percentage height , Whether the page becomes larger or smaller ,style.height All return this percentage
2) and offsetHeight Returns the height value of the object in different pages instead of the percentage value
5.clientWidth
Is the visible width of the object , Don't wrap scroll bar equilaterals , Changes with the display size of the window .
6.clientHieght
Page visible area high
7.scrollLeft
The distance from the leftmost side of the object to the left side of the object within the display range of the current window .
That is, when a horizontal scroll bar appears , The distance the scroll bar is pulled .
8.scrollTop
The distance from the top of an object to the top edge of the object within the range of the current window .
That is, when the vertical scroll bar appears , The distance the scroll bar is pulled .
9. On the body of the page : window.screenTop
10. Page body left : window.screenLeft
11. High screen resolution : window.screen.height
12. Width of screen resolution : window.screen.width
13. Screen available workspace height : window.screen.availHeight
版权声明
本文为[Nanqiao Jixu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220729530586.html
边栏推荐
- 手把手教你实现RecyclerView的下拉刷新和上拉加载更多
- 字符串的替换
- 反转一个链表<难度系数>
- Experiment 4: Data Preprocessing
- Use the method of onlayoutchangelistener to solve the problem of gettop = 0
- Airtest installation and introduction
- 构造函数与toString
- cesium坐标转换:不同坐标系之间的相互转换
- The starting point of the final end of the 15th day of the sprint to the big factory
- 7-34 删除重复字符(set用法)&&7-35 统计字符出现次数(unordered_map)
猜你喜欢

postgres+postgis+geoserver离线路径规划功能(记录)
![[Dahua cloud native] micro service chapter - service mode of five-star hotels](/img/fc/be18f39e4aa653efa8603ab63ff3f1.png)
[Dahua cloud native] micro service chapter - service mode of five-star hotels

Machine learning notes - determinant

广城云服务实现每天定时填写一日一报

Pycharm terminal PIP installation error: "PIP" item is recognized as the name of cmdlet, function, script file or runnable program

The collection palette in LabVIEW 2012 is imported into LabVIEW 2013

ViewPager 全面总结

7-34 删除重复字符(set用法)&&7-35 统计字符出现次数(unordered_map)

Arm bare metal (IV) -- exceptions and interrupts

1315. 祖父节点值为偶数的节点和(Medium)
随机推荐
Pyqt5 uses the built-in database sqllite
[Dahua cloud native] micro service chapter - service mode of five-star hotels
Navicat Premium 导入SQL文件
函数指针和指针函数
ARM裸机篇(四)——异常和中断
Flutter ListView 加载更多
shell脚本学习笔记——正则表达式
SQL requirements processing - count the number of Mondays to Sundays in a given year
CPU的基本工作流程
SmartTabLayout 简介
winform中网络开发
centos7安装MySQL8.0
7-34 delete duplicate characters (set usage) & 7-35 count the number of characters (unordered_map)
二进制的前导的零
链表打印(链表反转输出)
MATLAB提示:要使用 ‘xxx函数‘,则必须授权、安装并启用了以下产品:xxx toolbox
Cesium加载地形数据(cesiumlab制作地形数据),从源数据到地形服务
eventBus
Flutter基础
客户端与服务器通信项目5:C语言实现ls命令