scrolltop

Javascript: Programmatically scroll non-popup SELECT element to bottom in Chrome

痞子三分冷 提交于 2019-12-02 02:09:30
I have a SELECT element in a web page, and I'd like it to load scrolled to the bottom. In most browsers, I can do this: myselect.scrollTop = myselect.scrollHeight; Although scrollHeight is out of bounds, the browsers figure that out and limit it appropriately. Except in Google Chrome. I could file a bug report, but that doesn't help me with my immediate problem. So I tried this: myselect.scrollTop = myselect.scrollHeight - myselect.clientHeight; But that subtracted too much -- there were items below the bottom of the element. I also tried subtracting offsetHeight , but that was slightly worse.

原生js实现div随鼠标移动效果

社会主义新天地 提交于 2019-12-02 00:14:19
原生js实例demos: http://pandoraui.github.io/learning-javascript/lesson2/10.html 原生js常用事件: 当网页加载时候: onload和onunload事件 <body onload ="checkCookies()"> 或者window.οnlοad=function(){} 当图像加载的时候: 当鼠标移动到元素上时候\当鼠标移除元素的时候: onmouseover ommousein ommouseout <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <body> <div οnmοuseοver="mOver(this)" οnmοuseοut="mOut(this)" style="background-color:#D94A38;width:120px;height:20px;padding:40px;">Mouse Over Me</div> <script> function mOver(obj){ obj.innerHTML="Thank You" } function mOut(obj){ obj.innerHTML="Mouse Over Me" } <

Firefox scrollTop problem

折月煮酒 提交于 2019-12-01 22:46:14
I have a problem with Firefox scrollTop value and onscroll event. This works great in IE, Safari and Chrome but Firefox seems to lag. I tried to update some background position with the onscroll event, but when I take the handle and drag it up and down quickly, Firefox stops updating the scrollTop value and it causes some lag in my app. You can try this code and look in the Firefox console when dragging the handle and you will see the values something stops the updating : function SaveScrollLocation () { console.log(document.documentElement.scrollTop); } window.onscroll=SaveScrollLocation ;

原生JS和jQuery的offset,client,scroll对比

只谈情不闲聊 提交于 2019-12-01 17:38:55
原生 offsetTop //获取元素距离带有定位父元素的位置(没有则以body) offsetLeft offsetWidth //获取元素自身的大小(宽度和高度) 包括了border 和padding offsetHeight offsetParent //返回带有定位的父盒子 没有则是body //返回的值不带单位 clientTop //返回元素上边框大小 clientLeft //返回元素左边框大小 clientWidth //包括padding不包括border 返回值不带单位 clientHeight //高度 document.documentElement.scrollTop //返回被卷去的高度,不带单位 //可读可写 document.documentElement.scrollLeft document.documentElement.scrollWidth //返回自身实际的宽度(滚动宽度),不含边框,不带单位 document.documentElement.scrollHeight window.pageYOffset //页面被卷去 //可读不可写 window.pageXOffset window.scroll(x, y) //滚动窗口至文档中的特定位置 window.scroll(0, 100) //不加单位 //已废弃被scrollTo替代

下滚导航自动折叠

落爺英雄遲暮 提交于 2019-12-01 15:11:21
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>下滚隐藏导航</title> 6 </head> 7 <style> 8 *{ 9 padding: 0; 10 margin: 0; 11 } 12 #nav{ 13 height: 30px; 14 width: 100%; 15 background: blue; 16 position: fixed; 17 top: 0px; 18 transition:.5s; 19 } 20 #nav li{ 21 float: left; 22 width: 25%; 23 text-align: center; 24 line-height: 30px; 25 } 26 #cont{ 27 height: 2000px; 28 background:linear-gradient(#FB7EA8 20%,#F68FAC 50%,#E0D2EB); 29 margin-top: 30px; 30 } 31 </style> 32 <body> 33 <div id="nav"> 34 <ul> 35 <li>导航1</li> 36 <li>导航2</li> 37 <li>导航3</li> 38 <li>导航4</li> 39 </ul> 40 <

vue实现京东动态楼层效果

只谈情不闲聊 提交于 2019-12-01 13:11:04
页面效果如下 <template> <div> <h1>首页</h1> <section class="floor-nav" id="floorNavList"> <!-- 左侧楼层 --> <ul class="nav-list"> <li class="nav-list-item" v-for="(item, index) in floorNav" :key="item.id" @click="setFloorNavMountClick(index)">{{ item.name }}</li> </ul> </section> <!-- 右侧的内容区域 --> <section class="floor-item" v-for="item in floorList" :key="item.id"> <div class="floor-item-box"> <h2>{{ item.name }}</h2> </div> </section> </div> </template> <script> var TIMER = null export default { name: 'home', data() { return { floorNav: [ // 自定义左侧楼层数 { id: 1, name: 'F1' }, { id: 2, name: 'F2' }, { id: 3,

Height、clientHeight、scrollHeight、offsetHeight 、scrollTop、offsetTop

匆匆过客 提交于 2019-12-01 06:03:28
Height 返回当前文档中的<body>元素的高度 clientHeight 对于没有定义CSS或者内联布局盒子的元素为0,否则,它是元素内部的高度(单位像素),包含内边距,但不包括水平滚动条、边框和外边距。 clientHeight 包含 padding scrollHeight scrollHeight的值在有滚动条的情况下包括滚动条滚动出去的内容,没有滚动条时是和 clientHeight 相同。包括元素的padding,但不包括元素的border和margin。scrollHeight也包括 ::before 和 ::after 这样的伪元素。 有滚动条 scrollHeight 包含 溢出的内容+padding 没有滚动条 scrollHeight = clientHeight offsetHeight 包括元素的边框、内边距和元素的水平滚动条(如果存在且渲染的话),不包含:before或:after等伪类元素的高度。 offsetHeight 包含 border+padding+元素的水平滚动条 scrollTop 一个元素的 scrollTop 值是这个元素的顶部到视口可见内容(的顶部)的距离的度量。当一个元素的内容没有产生垂直方向的滚动条,那么它的 scrollTop 值为0。 offsetTop 当前元素相对于其 offsetParent 元素的顶部内边距的距离

Animate jQuery scrolltop

我只是一个虾纸丫 提交于 2019-12-01 04:25:51
问题 I have a scrollTop function in jQuery but I can't animate it. Is it possible? $(".loadmore").click(function() { $(this).toggleClass("up-arrow", 1000); $(window).scrollTop($('.docs').offset().top, 2000); }); 回答1: You can use animate() for this. Example code applied on a div is as follows : //Scroll to bottom $('div').animate({scrollTop: $('div').get(0).scrollHeight}, 3000); //$('div').get(0).scrollHeight - will give the full height of div. //scrollTop - will be used to animate from the current

页面滚动scroll到最底部 - 加载更多数据

╄→гoц情女王★ 提交于 2019-12-01 01:43:59
上拉内容区域,拉到底部实现分页功能,向后端请求更多数据加载到页面上 vue项目,使用纯js实现,网上显示了很多插件可以实现,我使用了几个,都不是我需要的效果,可能没研究明白,没办法只能原生实现,具体实现思路如下~ 思路:通过滚动条判断是否到内容底部 => 到底部后向后台请求下一页得数据 => 将请求得新数据拼接在老数据上 特别:需要判断请求的页数是否为第一页,如果是第一页不要拼接 怎么判断滚动条是否到最底部: 三个关键的点: 1:滚动条距离顶部的距离:document.documentElement.scrollTop||document.body.scrollTop 2:当前窗口内容的可视区域:document.documentElement.clientHeight || document.body.clientHeigh 3:滚动条内容的总高度:document.documentElement.scrollHeight||document.body.scrollHeight 一个关键函数: 一个监听滚动函数:window.addEventListener('scroll',()=>{}) 一个判定的等式:滚动条距离顶部 + 窗口可视区域 == 滚动条内容总高度,此时可以判定滚动条已经滚动到最底部 created(){ window.addEventListener(

uni-app聊天室|vue+uniapp仿微信聊天实例|uniapp仿微信App界面

笑着哭i 提交于 2019-12-01 00:24:55
一、介绍 运用UniApp+Vue+Vuex+swiper+uniPop等技术开发的仿微信原生App聊天室|仿微信聊天界面实例项目uniapp-chatroom,实现了发送图文消息、表情(gif图),图片预览、地图位置、长按菜单、红包/钱包、仿微信朋友圈等功能。 二、测试效果 H5 + 小程序 + App端测试效果如下,实测多端效果均为一致。( 后续大图统一展示App端 ) 二、技术选型 编辑器:HBuilder X 技术框架:uni-app + vue 状态管理:Vuex iconfont图标:阿里字体图标库 自定义导航栏 + 底部Tabbar 弹窗组件:uniPop(基于uni-app封装模态弹窗) 测试环境:H5端 + 小程序 + App端(三端均兼容) 高德地图:vue-amap ◆ 顶部导航栏headerBar 顶部导航栏采用的是自定义模式,具体可参看这篇文章: uni-app自定义导航栏按钮|uniapp仿微信顶部导航条 在pages.json里面配置globalStyle,将navigationStyle设为custom时,原生顶部导航栏不显示,这时就能自定义导航栏 "globalStyle": {"navigationStyle": "custom"} ◆ 引入公共样式/组件及全局弹窗 import Vue from 'vue' import App from '.