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
29
votes
9 answers

jQuery - ScrollTop without animation

How can I use the scrolltop without an animation This code works: var offTop = $('#box').offset().top; offTop = offTop-43; $('#mainCt').animate({scrollTop: '+=' + offTop + 'px'}, 400); And here are my (not working…
user970727
  • 1,947
  • 4
  • 22
  • 28
28
votes
2 answers

Choppy/Laggy scroll event on Chrome and IE

I am trying to have a content block always be shown to the user, even if he scrolls way down the page. He should also be able to scroll up and down the content block. Here is a fiddle with a stripped down version to show you what I…
Marcelo Mason
  • 6,750
  • 2
  • 34
  • 43
26
votes
1 answer

Set scrollTop and scrollLeft without JavaScript

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…
Yetispapa
  • 2,174
  • 2
  • 30
  • 52
24
votes
7 answers

Can't get scrollTop() to work in both Chrome & Firefox

I am having trouble getting the scrollTop() method to work in both Firefox and Chrome. I used $('body, html').scrollTop(); however, it doesn't work in Chrome. Only $('body').scrollTop(); works in Chrome. Any thoughts would be greatly appreciated.…
Jonny Cerveza
  • 243
  • 1
  • 2
  • 6
24
votes
2 answers

jQuery scrolltop firefox not working

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:…
seanlevan
  • 1,367
  • 3
  • 15
  • 33
24
votes
3 answers

Trigger $(window).scroll();

When I call $("body").animate({scrollTop: someValue}); I want $(window).scroll(function() { }); to be called too. How can I achieve that? I have tried with $(window).trigger("scroll") and $(window).triggerHandler("scroll") without success. The…
Sawny
  • 1,404
  • 2
  • 14
  • 31
21
votes
6 answers

How to get maximum document scrolltop value

I am making some plugin and I need to get maximum scrollTop value of the document. Maximum scrollTop value is 2001 , but $(document).height() returns 2668 and $('body')[0].scrollHeight gives me undefined. How to get 2001 through javascript/jquery?!
hjuster
  • 3,985
  • 9
  • 34
  • 51
20
votes
2 answers

Scroll element into view in scrollable container

I have a scrolling container with a hard coded height: .scrollingContainer { overflow: scroll; height: 400px; } This scrolling container contains a list of items, when I click on the item I want to scroll the container so that the item…
CLiown
  • 13,665
  • 48
  • 124
  • 205
18
votes
2 answers

Does WebKit have a clipping bug?

NB: I tidied up this question in 2021 to remove a dead link and make the code a live demo. With a cursory check, the problem appears to no longer exist in the current version of Chrome. Given a region where the line-height and any margins are n,…
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
16
votes
3 answers

Cross-Browser method for setting ScrollTop of an element?

For example I have I a div tag with the scroll bar on the right of the div tag. I want to show the div with the last line, so I have this: document.getElementById("divscroll").scrollTop = 250000; I can make it scroll to the end in Firefox but…
nvcnvn
  • 4,991
  • 8
  • 49
  • 77
16
votes
2 answers

javascript smooth scroll on click

I'm using this link: superContent It does two things at once: Jumps user to top of the page Performs this other (unrelated) ajax load function Everything works great, except I'm…
user1691389
  • 453
  • 1
  • 6
  • 16
15
votes
3 answers

jQuery animate scrollTop

I have quite a few section tags in a div with an overflow set to hidden. The code is along the lines of this:
content
content
I have it set up like this…
ayyp
  • 6,590
  • 4
  • 33
  • 47
15
votes
3 answers

get height for a div with overflow:auto;

i have a div with height:100px and overflow:auto the content is dynamic. i want scroll the div in the bottom i tried with $("#chat_content").scrollTop($("#chat_content").height()); but if the content is bigger than 100px…
Luca Romagnoli
  • 12,145
  • 30
  • 95
  • 157
15
votes
1 answer

Maintain scrollTop while inserting new sections above the current viewed elements (without glitching)

Here's one for the real JQuery UI geniuses: We have a extremely long form with sections loaded on demand (e.g. when an index/navigation is clicked, or as we scroll near the edges of the current section). When I load sections below the currently…
iCollect.it Ltd
  • 92,391
  • 25
  • 181
  • 202
15
votes
3 answers

scrollTop in mobile Safari not functioning

I have spent the last hour reading through the numerous questions on zooming and .scrollTop() and the variations of handlings and have tried at least 20 different things - everything that looked even remotely workable for my situation and I still…
Peter Oram
  • 6,213
  • 2
  • 27
  • 40
1
2
3
79 80