scrolltop

jquery-8 jquery如何处理css样式

人盡茶涼 提交于 2019-12-18 02:08:10
jquery-8 jquery如何处理css样式 一、总结 一句话总结: 1、如何获取网页的三个高? 1)可视区域的高 $(window).height(); 2)文档总高度 $(document).height(); 3)滚动的高 $(window).scrollTop(); 2、标签的三种类型的宽高是哪三种? height(); width(); innerHeight(); innerWidth(); outerHeight(); outerWidth(); 3、position()和offset()的区别是什么? position是相对父亲的位置 offset是相对窗口左上角的位置 二、jquery如何处理css样式 1、相关知识 CSS处理: 1.CSS样式 css(); css({}); 2.位置 offset(); position(); scrollTop(val); 3.尺寸 height(); width(); innerHeight(); innerWidth(); outerHeight(); outerWidth(); 4.获取三个高 1)可视区域的高 $(window).height(); 2)文档总高度 $(document).height(); 3)滚动的高 $(window).scrollTop(); 2、代码 position定位 1 <

Accounting for a fixed header with animate.scrolltop and (target).offset().top;

我与影子孤独终老i 提交于 2019-12-17 17:49:06
问题 This should be a pretty basic question, but i've thrown most of my morning at it, and at this point I'm close to throwing in the towel. I have not even a little bit of js foo -- but I found a nicely commented chunk of code that I'm hoping to use to animate anchor links it is: $(document).ready(function() { $('a[href*=#]').bind('click', function(e) { e.preventDefault(); //prevent the "normal" behaviour which would be a "hard" jump var target = $(this).attr("href"); //Get the target var

jQuery .scrollTop(); + animation

大兔子大兔子 提交于 2019-12-17 02:58:49
问题 I set the page to scroll to top when a button is clicked. But first I used an if statement to see if the top of the page was not set to 0. Then if it's not 0 I animate the page to scroll to the top. var body = $("body"); var top = body.scrollTop() // Get position of the body if(top!=0) { body.animate({scrollTop:0}, '500'); } The tricky part now is animating something AFTER the page has scrolled to the top. So my next thought is, find out what the page position is. So I used console log to

jQuery 滚动监听总结

大憨熊 提交于 2019-12-16 17:58:55
JQuery监听页面滚动总结 1、当前滚动的地方的窗口顶端到整个页面顶端的距离: var winPos = $(window).scrollTop(); 2、获取指定元素的页面位置: $(val).offset().top; 3、对页面滚动条滚动的监听:要放在页面加载的时候 $(window).scroll(function(event){ }); 4、设置滚动条到指定位置。$(window).scrollTop(offset)。 例如: jquery判断滚动条距离顶部的距离 //滚动监听显示回顶部 function jianting(){ $(window).scroll(function(){ // 滚动条距离顶部的距离 大于300px时 if($(window).scrollTop() >= 300){ $("#xiaohuojian").fadeIn(1000); // 开始淡入 } else{ $("#xiaohuojian").stop(true,true).fadeOut(1000); // 如果小于等于 300 淡出 } }); } //点击回到页面顶部 function huidingbu(){ $("#xiaohuojian").click(function(){ $("html,body").animate({scrollTop:"0px"},'slow');

JS-scrollTop、scrollHeight、clientTop、clientHeight、offsetTop、offsetHeight的理解

那年仲夏 提交于 2019-12-16 12:33:05
scrollTop, 可写(这些属性中唯一一个可写的元素) Element.scrollTop 属性可以获取或设置一个元素的内容垂直滚动的像素数。 一个元素的 scrollTop 值是这个元素的顶部到视口可见内容(的顶部)的距离的度量。当一个元素的内容没有产生垂直方向的滚动条,那么它的 scrollTop 值为0。 scrollTop 可以被设置为任何整数值,同时注意: 如果一个元素不能被滚动(例如,它没有溢出,或者这个元素有一个"non-scrollable"属性), scrollTop将被设置为0。 设置scrollTop的值小于0,scrollTop 被设为0 如果设置了超出这个容器可滚动的值, scrollTop 会被设为最大值. 看图理解: 返回顶部: element.scrollTop = 0 一个简单的返回顶部的例子,并且实现动画由快到慢 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>返回顶部</title> <style> #outer { height: 100px; width: 100px; padding: 10px 50px; border: 1px solid; overflow: auto; } </style> </head> <body> <div id=

JS特效(三大系列)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-15 20:57:07
一. offset系列 offset系列的5个属性 offsetLeft : 用于获取元素到最近的定位父盒子的左侧距离 计算方式: 当前元素的左边框的左侧到定位父盒子的左边框右侧 如果父级盒子没有定位, 那么会接着往上找有定位的盒子 如果上级元素都没有定位,那么最后距离是与body的left值 offsetTop : 用于获取元素到最近定位父盒子的顶部距离 计算方式:当前元素的上边框的上侧到定位父盒子的上边框下侧 如果父级盒子没有定位,那么会接着往上找有定位的盒子 如果上级元素都没有定位,那么最后距离是与body的top值 offsetWidth :用于获取元素的真实宽度(除了margin以外的宽度) offsetHeight : 用于获取元素的真实高度(除了margin以外的高度) offsetParent :用于获取该元素中有定位的最近父级元素 如果当前元素的父级元素都没有进行定位,那么offsetParent为body 与style.(left/top/width/height)的区别: offset系列的是只读属性,而通过style的方式可以读写 offset系列返回的数值类型(结果四舍五入),style返回的是字符串 offsetLeft 和 offsetTop 可以返回没有定位的元素的left值和top值,而style不可以 二. scroll系列 1

纯JS监听滚动到底部

本秂侑毒 提交于 2019-12-15 05:35:30
document . addEventListener ( 'scroll' , function ( ) { let ele = document . documentElement ; // 获得html let scrollTop = ele . scrollTop ; // 向上滚动的高度 let scrollHeight = ele . scrollHeight ; // 滚动内容区域总高度 let clientHeight = ele . clientHeight ; // 可见高度 if ( clientHeight + scrollTop >= scrollHeight ) { // 已经滚动到底部 } } ) 来源: CSDN 作者: 不许动一二三 链接: https://blog.csdn.net/yuanqi3131/article/details/103490949

滚动穿透

牧云@^-^@ 提交于 2019-12-13 12:49:19
滚动穿透 内层滚动带动外层 body.modal-open { position: fixed; } var ModalHelper = (function (bodyCls) { var scrollTop; return { afterOpen: function () { console.log(10); scrollTop = document.scrollingElement.scrollTop; document.body.classList.add(bodyCls); document.body.style.top = -scrollTop + 'px'; }, beforeClose: function () { console.log(20); document.body.classList.remove(bodyCls); document.scrollingElement.scrollTop = scrollTop; } }; })('modal-open'); /***进入遮罩层,禁止滑动***/ function stopScroll() { ModalHelper.afterOpen(); } /***取消滑动限制***/ function allowScroll() { ModalHelper.beforeClose() } 来源: https:/

移动端下拉滚动刷新

喜你入骨 提交于 2019-12-13 11:37:28
一、需求   移动端下拉到底,加载更多数据。由于网页的执行都是单线程的,在 JS 执行的过程中,页面会呈现阻塞状态。因此,如果 JS 处理的数据量过大,过程复杂,可能会造成页面的卡顿。传统的数据展现都以分页的形式,但是分页的效果并不好,需要用户手动点击下一页,才能看到更多的内容。有很多网站使用无限分页的模式,即网页视窗到达内容底部就自动加载下一部分的内容。 二、概念 clientHeight:视口(viewport)的高度,就是我们在浏览器中所能看到内容的高度; screenHeight:屏幕高度,实际移动设备的屏幕高度。 scrollHeight:真实内容的高度; scrollTop:视窗上面隐藏掉的部分。 三、原理 真实内容高度 - 视窗高度 - 上面隐藏的高度 < 20,作为加载的触发条件 四、实现方法 1,获取滚动条到文档顶部的距离 var scrollTop = document.documentElement.scrollTop; //或 var scrollTop = Math.ceil($(this).scrollTop()); 2,获取可视区高度 1 var v_height = document.documentElement.clientHeight; 2 //或 3 var v_height = $(this).height(); 3,获取文档总高度 1

jQuery smooth scroll full url including id

怎甘沉沦 提交于 2019-12-13 06:17:44
问题 Just wondering how to enable smooth scroll using full url. This is the nav <nav class="primary-nav"> <ul> <li><a href="http://domainname.com/">Home</a></li> <li><a href="#about">About</a></li> <li><a href="#services">Services</a></li> <li><a href="http://domainname.com/contact">Contact</a></li> </ul> </nav> Would like to use <nav class="primary-nav"> <ul> <li><a href="http://domainname.com/">Home</a></li> <li><a href="http://domainname.com/#about">About</a></li> <li><a href="http://domainname