Questions tagged [scrolltop]

The scrollTop method. An element's scrollTop is a measurement of the distance of an element's top to its topmost visible content.

An element's scrollTop is a measurement of the distance of an element's top to its topmost visible content.


When an element content does not generate a vertical scrollbar, then its scrollTop value defaults to 0.

scrollTop can be set to any integer value, however:

  • If the element can't be scrolled (e.g. it has no overflow or if the element is non-scrollable), scrollTop is set to 0.
  • If set to a value less than 0, scrollTop is set to 0.
  • If set to a value greater than the maximum that the content can be scrolled, scrollTop is set to the maximum.

The .scrollTop() method, in jQuery is used to get or manipulate the current vertical position of the scroll bar for the first element in the set of matched elements or set the vertical position of the scroll bar for every matched element.

For more on this subject, please refere to the jQuery page, until further updates.

1197 questions
191
votes
4 answers

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

What's the difference between: $(window).scrollTop() and $(document).scrollTop() Thanks.
frenchie
  • 51,731
  • 109
  • 304
  • 510
189
votes
12 answers

jQuery .scrollTop(); + animation

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()…
Juan Di Diego
  • 1,893
  • 2
  • 12
  • 4
178
votes
23 answers

Angular 5 Scroll to top on every Route click

I am using Angular 5. I have a dashboard where I have few sections with small content and few sections with so large content that I am facing a problem when changing router while going to top. Every time I need to scroll to go to top. How can I…
raihan
  • 2,225
  • 4
  • 14
  • 19
164
votes
11 answers

Animate scrollTop not working in firefox

This function works fine. It scrolls the body to a desired container's offset function scrolear(destino){ var stop = $(destino).offset().top; var delay = 1000; $('body').animate({scrollTop: stop}, delay); return false; } But not in…
Toni Michel Caubet
  • 19,333
  • 56
  • 202
  • 378
74
votes
9 answers

$(document).scrollTop() always returns 0

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:…
jetlej
  • 3,382
  • 6
  • 29
  • 41
67
votes
4 answers

Run ScrollTop with offset of element by ID

Trying to make the browser scroll to a specific ID with an added offset - $('html, body').animate({scrollTop: $('#contact').offset().top}, 'slow'); What I need to do is to set the offset by -100px. How can I accomplish this?
Staffan Estberg
  • 6,795
  • 16
  • 71
  • 107
58
votes
7 answers

How to scroll to top of a div using jQuery?

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..
// gridview inside..
My gridview will have custom pagination generated link buttons in it... I…
ACP
  • 34,682
  • 100
  • 231
  • 371
53
votes
5 answers

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

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…
Himanshu P
  • 9,586
  • 6
  • 37
  • 46
50
votes
6 answers

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

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…
saikofish
  • 1,744
  • 1
  • 15
  • 12
49
votes
4 answers

Why is body.scrollTop deprecated?

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 DOMElements? Background Info: I have a function that tries to increase (or…
Himanshu P
  • 9,586
  • 6
  • 37
  • 46
37
votes
1 answer

jQuery add and remove $(window).scroll(function()?

How can I remove and then add the $(window).scroll? I need to store a variable and reuse it after some event. // here i store my var $(window).scroll(function(){ myScroll = $(window).scrollTop() }); $("#itemUnbind").click(function(){ //…
Dee
  • 3,185
  • 10
  • 35
  • 39
32
votes
4 answers

scrollTop() returns 0 in Firefox, but not in Chrome

Not sure if there's another question regarding this, if so I apologize and please don't release the hounds. Using the html5 doctype and doing a quick console.log off my scroll listener that tells me the value of scrollTop() value. I'm basically…
lxndr
  • 702
  • 1
  • 11
  • 25
30
votes
3 answers

;Jquery: animate page down 100px from current screen position

I need to animate a scroll from the current screen position, down a set number of pixels. $('html,body').animate({ scrollTop: $(window).position().top += 100 }); or? $('html,body').animate({ scrollTop: '+=100px' });
android.nick
  • 11,069
  • 23
  • 77
  • 112
30
votes
3 answers

Append content to div and scroll/animate to bottom

I'm trying to make a div scroll to the bottom after adding new content (using append) Here is the main part: $('#textdiv').append('

Lorem ipsum dolor sit amet, solet nostrud concludaturque no eam. Ne quod recteque pri. Porro nulla zril mei eu. Eu…

mowgli
  • 2,796
  • 3
  • 31
  • 68
29
votes
4 answers

Find offset relative to parent scrolling div instead of window

I have a scrolling element inside a window. Say a division having a class "currentContainer" with overflow auto and that division contains huge amount of text so that it is definitely large enough to be scrolling. Now I have to do some calculations…
Arpita
  • 1,386
  • 1
  • 15
  • 35
1
2 3
79 80