10 examples of 'click to scroll top' in JavaScript

Every line of 'click to scroll 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
28scrollUpHelper() {
29 return this.app.waitForExist('~upScroll').click('~upScroll');
30}
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

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}
53scrollToTop(topOffset = 0) {
54 this.scrollToElement(this.doc.body, topOffset);
55}
35function scrollDown(){
36 var psconsole = $('#G2_output');
37 psconsole.scrollTop(
38 psconsole[0].scrollHeight - psconsole.height()
39 );
40}
36containerClick(e: any): void {
37 if (e.target === e.currentTarget) {
38 const offsetY = e.offsetY - this.naturalThumbSize * .5;
39 const thumbPositionPercentage = offsetY * 100 / this.containerElement.clientHeight;
40 const value = thumbPositionPercentage * this.viewElement.scrollHeight / 100;
41 this.scrollbarRef.scrollTo({top: value, duration: this.scrollbarRef.scrollToDuration});
42 }
43}
57scrollPageToTop() {
58 this.$.headerPanelMain.scrollToTop(true);
59}
38scrollToTop() {
39 $('html, body').animate({
40 scrollTop: 0,
41 }, 500);
42}
40scrollToTop() {
41 this.refs._scrollView.scrollTo({ x: 0, y: 0, animated: true })
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}
11function showGoToTop() {
12 $(window).scroll(function(){
13 if ($(this).width() <= 620 && $(this).scrollTop() > 100) {
14 if($('#goToTop').is(":hidden")) {
15 $('#goToTop').css({display: "flex"}).hide().fadeIn();
16 }
17 } else {
18 $('#goToTop').fadeOut();
19 }
20 });
21}

Related snippets