scrolltop

offsetHeight ,offsetWidth ,offsetLeft offsetTop clientWidth clientHeight scrollHeight scrollWidth scrollLeft scrollTop

不羁的心 提交于 2019-12-20 20:29:12
offsetHeight ,offsetWidth ,offsetLeft offsetTop clientWidth clientHeight scrollHeight scrollWidth scrollLeft scrollTop,返回的都是纯数字 1、元素的偏移量 元素的可见大小是由其高度、宽度决定,包括所有的内边距、滚动条和边框大小(不包括外边距)。 offsetHeight :元素在垂直方向上占用的空间大小,以像素计算。包括元素的高度,水平滚动条高度,上下边框高度。 offsetWidth :元素在水平方向上占用的空间大小,以像素计算。 包括元素的宽度,垂直滚动条高度,左右边框高度。 offsetLeft :元素的左外边框至包含元素的左内边框之间的像素距离。 offsetTop :元素的上外边框至包含元素的上内边框之间的像素距离。 offsetParent :元素的包含元素,找离自己最近有定位的父元素。元素的offsetParent不一定和parentNode相等。例如,<td>元素的offsetParent是祖先元素<table>,因为<table>是在DOM层次中距离<td>最近的一个具有大小的元素。 返回一个指向最近的(指包含层级上的最近) 包含该元素的定位元素或者最近的 table, td, th, body 元素 。当元素的 style.display 设置为

body.scrollTop vs documentElement.scrollTop vs window.pageYOffset vs window.scrollY

岁酱吖の 提交于 2019-12-20 08:56:30
问题 When trying to find out how much a web page has been scrolled from the top, which of these should one use: document.body.scrollTop , document.documentElement.scrollTop , window.pageYOffset , window.scrollY Which one(s) would I choose in these 2 separate scenarios: a) If I wanted maximum compatibility (across the main browsers used currently)? b) If I wanted code that was most standards compliant/future-proof/strict-mode-compatible (but didn't care about supporting old/non-standard browsers)?

scrollTo gets overridden when using jQuery Mobile

假装没事ソ 提交于 2019-12-20 05:45:14
问题 I am creating a mobile web app with jQuery Mobile and would like to hide the search bar above the visible area. So the user would need to pull the page down to see the search bar. I'm thinking the best way to do that is to define the search bar as usual then on page load manually set the scroll position, say down 55px. Here's my code: $(document).ready( function() { $("html,body").scrollTop(55); } The problem is, I can see upon refreshing the page it is hidden from view, but once it has fully

解决移动端滚动穿透问题(兼容ios,android)

本小妞迷上赌 提交于 2019-12-20 01:23:52
解决问题。 网上找了一圈大多都是; overflow: hidden 页面有弹出层时将overflow: hidden样式添加到 html 上,禁用 html 和 body 的滚动条,但是这个方案移动端根本无用!!!!,pc端也有两个缺点; 1.由于 html 和 body的滚动条都被禁用,弹出层后页面的滚动位置会丢失,需要用 js 来还原。 2.页面的背景还是能够有滚的动的效果。 方案二:touchmove + preventDefault modal.addEventListener('touchmove', function(e) { e.preventDefault(); }, false); 如果是vue项目在弹层最外层父容器添加属性: @touchmove.prevent 次方案适用于你的弹层内部不需要滚动。 终极方案: position: fixed 如果只是加fixed,滚动条的位置同样会丢失。 所以如果需要保持滚动条的位置需要用 js 保存滚动条位置关闭的时候还原滚动位置。 <script type="text/javascript"> //解决遮罩层滚动穿透问题,分别在遮罩层弹出后和关闭前调用 const ModalHelper = ( (bodyCls) =>{ let scrollTop; return { afterOpen: function () {

点击按钮回到页面顶端的几种方式

前提是你 提交于 2019-12-19 13:19:13
一,使用 scrollbar 滚动条 (使用锚点的方式) <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>点击回到页面顶端</title> </head> <body style="height:2000px;"> <button id="test" style="position:fixed;right:0;bottom:0">回到顶部</button> <script> test.onclick = function(){ document.body.scrollTop = document.documentElement.scrollTop = 0; } </script> </body> </html> 二,scrollTop:scrollTop属性表示被隐藏在内容区域上方的像素数。元素未滚动时,scrollTop的值为0,如果元素被垂直滚动了,scrollTop的值大于0,且表示元素上方不可见内容的像素宽度 由于scrollTop是可写的,可以利用scrollTop来实现回到顶部的功能 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>点击回到页面顶端</title> </head>

回到顶部和返回首页jquery插件

…衆ロ難τιáo~ 提交于 2019-12-19 12:15:48
打造最全的CMS类教程聚合! 第一种方法:在网页<body></body>之间插入: <!--返回顶部开始--> < div id = "full" style = "width:50px; height:95px; position:fixed; left:50%; top:425px; margin-left:493px; z-index:100; text-align:center; cursor:pointer;" > < a > < img src = "images/up.png" border = 0 alt = "返回顶部" > </ a > </ div > < script src = "/js/gotop.js" type = "text/javascript" > </ script > <!--返回顶部结束--> 修改图片路径和js路径,保证图片和JS都 能打开就行了 ! JS文件下载: 点击下载 第二种方法:回到顶部功能:在网页<body></body>之间插入: <!--引入jquery库文件--> < script type = "text/javascript" src = "https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" > </ script > <!-

Snap To Top of Div/Element on Scroll

对着背影说爱祢 提交于 2019-12-19 03:39:08
问题 Can anyone recommend a "best" approach for snapping the scrollbar to the top of an element when scrolling down a page? For example, if my layout was as follows: <div id="section-one" style="width: 100%; height: 600px;"> Section One </div> <div id="section-two" style="width: 100%; height: 600px;"> Section Two </div> <div id="section-three" style="width: 100%; height: 600px;"> Section Three </div> <div id="section-four" style="width: 100%; height: 600px;"> Section Four </div> If the user was

jQuery accordion, scroll beginning of clicked tab to the top, doesn't work if expanded tab is above the one being clicked?

安稳与你 提交于 2019-12-18 12:36:31
问题 Got a little bit of a problem with getting my jquery accordion to do what I want. I always want the tab that is being clicked to be scrolled to a fixed amount of pixels from the top of the page, and I kinda got it working. But whenever the active tab is above the tab being clicked and if the page already is scrolled down a bit, the top and parts of the content of the clicked tab is scrolled up past the top of the page. This is what i got: $(function() { $("#accordion").accordion({ autoHeight:

vue移动端添加加载更多

冷暖自知 提交于 2019-12-18 07:36:26
mounted () { //引入滚动方法 window.addEventListener('scroll', this.touchmove) }, methods: { touchmove(e){ //变量scrollTop是滚动条滚动时,距离顶部的距离 var scrollTop = document.documentElement.scrollTop||document.body.scrollTop; //变量wndowHeight是可视区的高度 var windowHeight = document.documentElement.clientHeight || document.body.clientHeight; //变量scrollHeight是滚动条的总高度 var scrollHeight = document.documentElement.scrollHeight||document.body.scrollHeight; //滚动条到底部的条件 if(scrollTop+windowHeight==scrollHeight){ //写后台加载数据的函数 console.log("距顶部"+scrollTop+"可视区高度"+windowHeight+"滚动条总高度"+scrollHeight); }} } 来源: CSDN 作者: Establish_bug

javascript smooth scroll on click

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-18 04:34:13
问题 I'm using this link: <a class="" onclick="location.href='#top'" href="superContent">superContent</a> It does two things at once: Jumps user to top of the page Performs this other (unrelated) ajax load function Everything works great, except I'm trying to figure out how to get it to scroll to the top more smoothly. I've tried adding .scroll to attach it to my jquery scrollTo plugin, but nothing happens, which probably has something to do with the fact that I'm using javascript onclick, while