scrolltop

set scrollTop and scrollLeft without javascript

雨燕双飞 提交于 2019-11-27 01:39:34
问题 I have a question about the scrollTop and scrollLeft properties. I would like to set these properties in my div without using JavaScript (jquery). Is this possible? My problem is, I have a program which interprets the HTML code and the divs which I scrolled have the value zero when the program interpret the code. The program can't read the scrollTop or scrollLeft value. Exists a HTML-tag like: <div scrollLeft="300" scrollTop="200"></div> 回答1: I'm afraid that this is not possible using CSS

文本框根据输入内容自适应高度 (没有滚动条)

有些话、适合烂在心里 提交于 2019-11-26 19:49:51
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>文本框根据输入内容自适应高度</title> <style type="text/css"> h2 { text-align: center; margin: 50px auto; } #textarea { display: block; margin: 0 auto; overflow: hidden; width: 550px; font-size: 14px; height: 18px; line-height: 24px; padding: 2px; } textarea { outline: 0 none; border-color: rgba(82, 168, 236, 0.8); box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 8px rgba(82, 168, 236, 0.6); } </style> <script> /*** * 文本框根据输入内容自适应高度 * @param {HTMLElement} 输入框元素 * @param {Number} 设置光标与输入框保持的距离(默认0) *

jQuery scrolltop firefox not working

余生长醉 提交于 2019-11-26 19:07:47
This script: function onscroll(){ document.getElementById("divs").style.top=""+$('body').scrollTop()+"px"; } Fiddle: http://jsfiddle.net/Hed2J/1/ Doesn't work on the latest Firefox version! What am I doing wrong? :) Thanks for the help! Edit: Edited with JSFiddle and full script :) as attached to an onscroll event Try this fiddle, it is working in chrome, ie and the latest version of mozilla : http://jsfiddle.net/Hed2J/3/ I replace $('body').scrollTop() with $(window).scrollTop() . A little off-topic, but if you want to animate using scrolltop, you must do $('html,body').animate({scrollTop:0},

Call Scroll only when user scrolls, not when animate()

谁说我不能喝 提交于 2019-11-26 18:27:08
问题 I have a few links across the page with the purpose of "going to the top", accomplished by scrolling the page to the top with a nice animation. I've noticed that sometimes while the page is scrolling the user will want to scroll back down, for example, but this is not possible. The screen will only stutter but will continue animating until it reaches the top. I want to stop the animation if the user attempts to scroll, therefore I wrote this code: $('#gototop').click(function() { $('body')

$(window).scrollTop() vs. $(document).scrollTop()

寵の児 提交于 2019-11-26 18:06:59
What's the difference between: $(window).scrollTop() and $(document).scrollTop() Thanks. Bodman They are both going to have the same effect . However, as pointed out in the comments: $(window).scrollTop() is supported by more web browsers than $('html').scrollTop() . First, you need to understand the difference between window and document. The window object is a top level client side object. There is nothing above the window object. Javascript is an object orientated language. You start with an object and apply methods to it's properties or the properties of it's object groups. For example,

How do I get the offset().top value of an element without using jQuery?

醉酒当歌 提交于 2019-11-26 17:39:56
问题 I'm programming a single-page application using the Angular framework. I'm new to it. I've read this guide to help me understand the fundamental differences between jQuery and Angular and I'd like to follow this guidance as much as possible and NOT use jQuery. Except that jQuery helps get around some of the browser incompatibilities and provides a useful library of functions, like being able to know the top position of an element from the top of the window, as in $('element').offset().top .

$(document).scrollTop() always returns 0

只愿长相守 提交于 2019-11-26 17:39:37
问题 I'm simply trying to do something once the scroll position of the page reaches a certain height. However scrollTop() is returning 0 or null no matter how far down I scroll. This is the help function I'm using to check the scrollTop() value: $('body').click(function(){ var scrollPost = $(document).scrollTop(); alert(scrollPost); }); I've tried attaching scrollTop() to $('body') , $('html') and of course $(window) , but nothing changes. Any ideas? 回答1: For some reason, removing 'height: 100%'

The same old issue, .scrollTop(0) not working in Chrome & Safari

两盒软妹~` 提交于 2019-11-26 17:07:45
问题 First, let me point out, i've googled and even looked at answers on here like this and this, however, I'm still yet to find a working solution for my case. I've designed a page that has several fixed elements covering the page and makes of html5/css3 to create a clean "mask" over the main document, thus allowing the body scroll bar to still scroll the underlying content. In firefox and ie (bleh), scrollTop(0) is working perfect. However, as stated by the question, not so much in my fav

Why is body.scrollTop deprecated?

纵然是瞬间 提交于 2019-11-26 16:31:29
问题 It seems body.scrollTop (and body.scrollLeft ) are deprecated in ES5 strict-mode. What is the reason for this, given that it still seems okay to use these properties on other DOMElement s? Background Info: I have a function that tries to increase (or decrease, as specified) the scrollTop values of all the ancestors of an element , till one of these actually changes. I am wondering if, to stay complaint with strict-mode, I should specifically check against the body element as the chain of

offsetLeft,Left,clientLeft的区别

拜拜、爱过 提交于 2019-11-26 15:41:59
假设 obj 为某个 HTML 控件。 obj.offsetTop 指 obj 相对于版面或由 offsetParent 属性指定的父坐标的计算上侧位置,整型,单位像素。 obj.offsetLeft 指 obj 相对于版面或由 offsetParent 属性指定的父坐标的计算左侧位置,整型,单位像素。 obj.offsetWidth 指 obj 控件自身的绝对宽度,不包括因 overflow 而未显示的部分,也就是其实际占据的宽度,整型,单位像素。 obj.offsetHeight 指 obj 控件自身的绝对高度,不包括因 overflow 而未显示的部分,也就是其实际占据的高度,整型,单位像素。 我们对前面提到的 offsetParent 作个说明。 offsetParent 获取定义对象 offsetTop 和 offsetLeft 属性的容器对象的引用。offsetTop 与 offsetParent 很复杂,不同浏览器有不同解释,浮动一下解释又不同了,所以我们一般只要理解通过二者可以获得控件在浏览器中的绝对位置即可。 以上属性在 FireFox 中也有效。 另外:我们这里所说的是指 HTML 控件的属性值,并不是 document.body,document.body 的值在不同浏览器中有不同解释(实际上大多数环境是由于对 document.body 解释不同造成的