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
14
votes
5 answers

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

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…
Martin
  • 233
  • 1
  • 3
  • 14
14
votes
2 answers

Scroll to top of the page using jquery animate

I want to put to the top bottom of the page which should scroll the page to the top. However I want the scrolling process to have animated effect. I think it is possible by using animate but have no idea how to ? Please help. Thanks
Narendra Bista
  • 279
  • 1
  • 2
  • 6
13
votes
3 answers

Autoscroll div with jQuery to the bottom after appending

I have a div class='messages'. I add date to this div via jQuery.append() Here are the styles: .messages { border: 1px solid #dddddd; padding:10px; height: 400px; overflow-x:visible; overflow-y: scroll; -webkit-border-radius:…
f1nn
  • 6,989
  • 24
  • 69
  • 92
12
votes
3 answers

Scrolling/Scrollbar Locks After Scrolltop Animation

I've got a few anchors that link to specific sections (using hashtags) within the page, and ones that scroll to the top or bottom of the document window. $("html, body").animate({ scrollTop: $(document).height() }, 2000); However, as soon as the…
cqde
  • 695
  • 5
  • 13
  • 22
11
votes
4 answers

How to maintain vertical scroll when updating Angular 5 data table?

I'd like to frequently update my data table (Covalent td-data-table with several ng-template) with new data pulled from a JSON REST API. More rows than will fit on browser so user may need to scroll vertically. But when I update the data in the…
bunt
  • 302
  • 2
  • 13
  • 25
11
votes
4 answers

jQuery animating scroll top to 0 not working on Windows Phone

I have written a website which has a function that scrolls the users view to the top of the page. The call in question is: $('html,body').animate({scrollTop:0}, 150, 'swing'); This works fine on all desktop browsers, but on Windows Phone, it only…
topherg
  • 4,203
  • 4
  • 37
  • 72
10
votes
13 answers

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

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…
SpYk3HH
  • 22,272
  • 11
  • 70
  • 81
10
votes
3 answers

jQuery scrollTop inconsistent across browsers

In Chrome and Safari, $("body").scrollTop(1000) goes where expected. In IE and FF, nothing happens. In IE and FF, $(window).scrollTop(1000) works, but they go to different places. It also works in Chrome and Safari, but they both go to a different…
Nathan Loyer
  • 1,339
  • 10
  • 20
10
votes
2 answers

How to find the element position relative to it's parent to scroll it visible

I have a div with lots of elements inside it, and overflow: scroll. Then i want to be able to scroll the nth element in view. I set a fiddle to it, but I can't find the expression to get the element position relative to the…
ariel
  • 15,620
  • 12
  • 61
  • 73
9
votes
1 answer

How to use scrollPositionRestoration in RouterModule.forchild(); ? How to make the page always scroll at top after page navigation?

scrollPositionRestoration : 'top' is not working for RouterModule.forchild()? Is there any solution in angular 7 to make sure that page always scroll top after navigation?
9
votes
4 answers

How to create a color transition controlled by window scroll

I have written some simple jQuery to have the background of my navbar change opacity from transparent to blue relative to the users scroll position. $(window).scroll(function(){ var range = $(this).scrollTop(); var limit = 450; var calc =…
Jcode
  • 223
  • 1
  • 11
9
votes
4 answers

NSScrollView scrollToTop

Does anyone know the correct way to scroll the NSScrollView to the top? I was looking for an equivalent to the UIView's scrollToTop method. This is what I have so far, but its not quite right under all situations [self.contentView…
user961889
  • 351
  • 2
  • 12
8
votes
1 answer

Moving element on Window scroll

You'll see in this JsFiddle https://jsfiddle.net/xpvt214o/402281/ there is an image scrolling within another one on window scroll. How can I modify the below so that it doesn't start scrolling until it hits that element (after all the br tags)? I've…
sarah3585
  • 637
  • 13
  • 37
8
votes
2 answers

Scroll to top not working for safari

I am calling this javascript on page load document.body.scrollTop = document.documentElement.scrollTop = 0; I want html page starts from top when loaded, above javascript working fine for chrome, safari(macbook) but not working for safari on…
Lalji Gajera
  • 471
  • 1
  • 5
  • 10
8
votes
1 answer

Scroll RecyclerView Scroll to position always on top

I'm using linear layout manager and RecyclerView with a LinearLayout Manager to populate some list of items. When I'm displaying the recyclerview for the first time and I use: linearLayoutManager.scrollToPosition(desiredindex); it scrolls to the…
erluxman
  • 18,155
  • 20
  • 92
  • 126
1 2
3
79 80