
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to stop the loop for JavaScript scroll down?
To stop the loop, use clearInterval() in JavaScript.
Example
Following is the code −
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <body> <script> var start = 0; var limit = 200; var scroll = setInterval(() => this.startScrollDown(), 20); function startScrollDown() { window.scrollBy(0, 1000); console.log(start) if (start == limit) clearInterval(scroll); start++; } </script> </html>
To run the above program, save the file name anyName.html(index.html) and right click on the file. Select the option “Open with live server” in VS Code editor.
Output
This will produce the following output −
- Related Questions & Answers
- How to detect scroll up and scroll down in android listView?
- How to detect Scroll Up & Scroll down in Android ListView using Kotlin?
- How to scroll down using Selenium WebDriver with Java?
- How to stop a loop with a stop button in Tkinter?
- How to slide down a navigation bar on scroll with CSS and JavaScript?
- How to hide a navigation menu on scroll down with CSS and JavaScript?
- How to scroll down the page till page end in the Selenium WebDriver?
- How to scroll down a webpage in selenium using Java?
- How to scroll the Page up or down in Selenium WebDriver using java?
- How to Scroll Down or UP a Page in Selenium Webdriver?
- How to stop an infinite loop safely in Python?
- How to scroll up/down a page using Actions class in Selenium?
- Explain for. . .of loop JavaScript.
- Is their JavaScript scroll event for iPhone/iPad?
- How to show for loop using a flowchart in JavaScript?
Advertisements