scrolltop

How to scroll to top of a div using jQuery?

淺唱寂寞╮ 提交于 2019-11-28 17:21:36
问题 I have a gridview inside a div.. I want to scroll to top of the div from the bottom of the div using jquery.. Any suggestion.. <div id="GridDiv"> // gridview inside.. </div> My gridview will have custom pagination generated link buttons in it... I will scroll to top of the div from the bottom of the link button click ... protected void Nav_OnClick(object sender, CommandEventArgs e) { LinkButton lb1 = (LinkButton)sender; //string s = lb1.ID; ScriptManager.RegisterClientScriptBlock(lb1, typeof

移除事件的兼容性处理

半腔热情 提交于 2019-11-28 15:42:24
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <input type="button" value="按钮" id="btn"> <script src="common.js"></script> <script> var btn = my$('btn'); function btnClick() { alert('hello'); // 移除事件 removeEventListener(btn, 'click', btnClick); } addEventListener(btn, 'click', btnClick); </script> </body> </html> common代码 function my$(id) { return document.getElementById(id); } // 处理浏览器兼容性 // 获取第一个子元素 function getFirstElementChild(element) { var node, nodes = element.childNodes, i = 0; while (node = nodes[i++]) { if (node.nodeType === 1) {

jquery的scrollTop方法

前提是你 提交于 2019-11-28 14:51:48
scrollTop方法设置或返回备选元素的垂直滚动条位置。 提示:当滚动条位于最顶部时,位置是0 当用于返回位置时: 该方法返回第一个匹配元素的滚动条的垂直位置 当用于设置位置时: 该方法设置所有匹配元素的滚动条的垂直位置 语法: 返回垂直滚动条位置:$(selector).scrollTop(); 设置垂直滚动条位置:$(selector).scrollTop(position); //position以像素为单位的垂直滚动条位置 来源: https://www.cnblogs.com/sjzgk/p/11410809.html

滑动加载

佐手、 提交于 2019-11-28 12:45:02
项目中有用到加载更多的功能,本来想做滑动加载的,但是一直没有研究出来,总是会多次触发,刚刚还故意去想当时怎么想的,怎么会出现那样的情况,可惜,没有写出来,现在把正确的解题思路总结下: 1.滑动加载首先触发的scroll事件,scroll事件,那么肯定就有一个scrollTop; var scrollTop=document.body.scrollTop,得到随时滑动的scrollTop; 2、得到窗口高度:window.innerHeight   document.body.clientHeight;//容器的真实高度(包括隐藏起来的) 定义变量var range=50;为距离底部多高,触发加载 再定义一个变量 var totalHeight = scrollTop + window.innerHeight;   if(document.body.clientHeight - 50 < totalHeight) {        loadMore();// 触发加载函数   }   var num=0;   function loadMore() {     var news = document.getElementById('news');     news.innerHTML+=" <li class='news__item'>"+ num +"、hello world<

jQuery window.scroll move div vertical in opposite direction

社会主义新天地 提交于 2019-11-28 12:35:47
问题 I have a div that scrolls down on the page scroll and when I scroll up the div scrolls up. I would like the opposite This is the code: // SCROLL BUTTON // -- iPhone picture should scroll in when down and down when up jQuery(window).scroll(function(){ jQuery(".iphonepic").stop().animate({ "top": (jQuery(window).scrollTop() - 0.00) + "px"}, "slow"); }); So when you scroll down, the div should go up vertically not the same as the scroll direction. Fiddle demo: http://jsfiddle.net/khaleelm/sQZ9G

HTML DOM 事件(实现一个简单的回到顶部功能)

╄→尐↘猪︶ㄣ 提交于 2019-11-28 10:19:19
HTML DOM 事件允许Javascript在HTML文档元素中注册不同事件处理程序。 事件通常与函数结合使用,函数不会在事件发生前被执行! (如用户点击按钮)。 利用onscroll事件写一个回到顶部功能,代码如下: <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>Document</title> <style> *{margin: 0;padding: 0;} #mybtn{position: fixed;height: 40px;width: 100px;background: red;border: none;border-radius: 5px;right: 20px;bottom: 20px;cursor: pointer;display: none;} #mybtn:hover{background-color: #888888;color: #FFFFFF;} </style> </head> <body>

clientHeight、offsetHeight和scrollHeight

佐手、 提交于 2019-11-28 10:01:48
我的话:以下是从网上找到的比较好的解释clientHeight、offsetHeight和scrollHeight等概念的东西,这个太难了,理解的再好都能混淆不清,保存下来永久记忆。 clientHeight、offsetHeight和scrollHeight 我们这里说说四种浏览器对 document.body 的 clientHeight、offsetHeight 和 scrollHeight 的解释,这里说的是 document.body,如果是 HTML 控件,则又有不同, 点击这里 查看。 这四种浏览器分别为IE(Internet Explorer)、NS(Netscape)、Opera、FF(FireFox)。 文尾的重要说明比较重要,请注意。 clientHeight 大家对 clientHeight 都没有什么异议,都认为是内容可视区域的高度,也就是说页面浏览器中可以看到内容的这个区域的高度,一般是最后一个工具条以下到状态栏以上的这个区域,与页面内容无关。 offsetHeight IE、Opera 认为 offsetHeight = clientHeight + 滚动条 + 边框。 NS、FF 认为 offsetHeight 是网页内容实际高度,可以小于 clientHeight。 scrollHeight IE、Opera 认为 scrollHeight

页面滚动,返回顶部按钮显示/隐藏

梦想与她 提交于 2019-11-28 09:57:34
要获取当前页面的滚动条纵坐标位置: document.documentElement.sctrollTop; 而不是: document.body.scrollTop; documentElement对应的是html标签,而body对应的是body标签 在w3c标准下,document.body.scrollTop恒为0,需要用document.documentElement.scrollTop代替 window.scroll = function(){ if(document.documentElement.scrollTop+document.body.scrollTop >50){   document.getElementById('#test').style.display ="block"; }else{   document.getElementById("#test").style.display = "none"; } } 来源: https://www.cnblogs.com/sjzgk/p/11403936.html

页面重新加载后滚动条位置不变

拈花ヽ惹草 提交于 2019-11-28 08:51:38
<script type= "text/javascript" > //重新加载后滚动条回到原来的位置 function window.onload() { var arr; //cookie中保存的有值,则将滚动条返回到原来的位置 if (arr = document.cookie.match(/scrollTop=([^;]+)(;|$)/)) { document.documentElement.scrollTop = parseInt(arr[1]); document.body.scrollTop = parseInt(arr[1]); } } //页面刷新前保存滚动条位置信息到cookie function window.onbeforeunload() { var scrollPos; if ( typeof window.pageYOffset != 'undefined' ) { scrollPos = window.pageYOffset; } else if ( typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat' ) { scrollPos = document.documentElement.scrollTop; } else if ( typeof

vue中记录页面的滚动距离

牧云@^-^@ 提交于 2019-11-28 08:07:05
业务需求:pageOne页面是一个商品列表页面,在这个页面点击商品,就会跳转到pageTwo商品详细页面。此时再从pageTwo页面返回到pageOne页面时,pageOne页面需要做到:1.记录pageOne之前的滚动的距离。2.不重新请求数据。而从其它页面进入到pageOne页面时,pageOne页面不需要记录之前的滚动距离和需要重新请求数据。 1.使用keep-alive组件的实现方法 App.vue <template> <div id="app"> <div id="nav"> <router-link to="/other">other</router-link> | <router-link to="/page-one">page-one</router-link> | <router-link to="/page-two">page-two</router-link> </div> <div class="container"> <!-- 使用keep-alive是为了缓存page-one组件内部scroll的值 --> <keep-alive> <router-view/> </keep-alive> </div> </div> </template> page-one.vue <template> <div class="page-one" ref=