10 examples of 'js scroll to top' in JavaScript

Every line of 'js scroll to top' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
35function scrollDown(){
36 var psconsole = $('#G2_output');
37 psconsole.scrollTop(
38 psconsole[0].scrollHeight - psconsole.height()
39 );
40}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

53scrollToTop(topOffset = 0) {
54 this.scrollToElement(this.doc.body, topOffset);
55}
492private scrollToBottom() {
493 if (this.stayWithLatest) {
494 $('html, body').scrollTop($(document).height());
495 }
496}
36function scroll_to(delta) {
37
38 if (delta < 0 ) {
39
40 delta = -scrollinc;
41 } else {
42
43 delta = scrollinc;
44 }
45
46 delta = delta * deltaKoef;
47
48 var listWidth = scroller.find('.dslca-section-scroller-content').width();
49 var contentWidth = scroller.width();
50
51 if ( listWidth <= contentWidth ) return false;
52
53 var scrollMax = listWidth - contentWidth + 10;
54
55 delta = parseInt(scrollInner.style.left || 0) - delta;
56 delta = delta >= 0 ? 0 : delta;
57 delta = delta <= -scrollMax ? -scrollMax : delta;
58
59 scrollInner.style.left = delta + 'px';
60}
3function scroll () {
4 if (window.location.hash === '') return
5 const anchor = $j('a[href="' + window.location.hash + '"]')
6 if (anchor) $j(window).scrollTop(anchor.offset().top)
7}
1function scroll (offsetTop) {
2 [document.body, document.documentElement].forEach((ele) => {
3 // eslint-disable-next-line
4 TweenLite.to(
5 ele,
6 0.4,
7 {
8 scrollTop: offsetTop,
9 ease: Power2.easeOut // eslint-disable-line
10 }
11 )
12 })
13}
16scrollToTop() {
17 $('#scroll-top').on('click', function(e) {
18
19 if( e ) {
20 e.preventDefault();
21 e.stopPropagation();
22 }
23
24 $('html,body').animate( { scrollTop: 0 }, 750 );
25 return false;
26 });
27}
38scrollToTop() {
39 $('html, body').animate({
40 scrollTop: 0,
41 }, 500);
42}
19function scroll_to_bottom() {
20 const messages = document.getElementById("messages");
21 const rect = messages.getBoundingClientRect();
22 messages.scrollTop = messages.scrollHeight - rect.height + 1;
23}
37function doScroll() {
38 var scroll = $(window).scrollTop();
39 var windowHeight = $(window).height();
40 var documentHeight = $(document).height();
41
42 var heightLessScroll = (documentHeight - windowHeight) - scroll;
43
44 if (heightLessScroll <= MINIMUM_HEIGHT_FOR_TO_LOAD) {
45 // $('.show-more').trigger('click');
46 }
47}

Related snippets