All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

Auto Scrolling Page Using jQuery

Last Updated : Jul 1, 2023

IN - jQuery HTML | Written & Updated By - Riya

In this tutorial we will show you how to scroll the webpage automatically using jQuery and HTML. We also provide auto scroll, manual scroll and stop scroll function to give full control to user and also to increase user experience.

You may also like smooth scrolling to div using jQuery.

Auto Scrolling Page Using jQuery

To Auto Scroll The Page It Takes Only One Step:-

  1. Make a HTML file and define markup, scripting and styling

Step 1. Make a HTML file and define markup, scripting and styling

We make a HTML file and save it with a name auto_scroll.html

<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function page_scroll()
{
 $("html, body").animate({ scrollTop: $(document).height() }, 20000);
}
function stop_scroll()
{
 $("html, body").stop();
}
</script>
<style>
body
{
 text-align:center;
 width:100%;
 margin:0 auto;
 padding:0px;
 font-family:helvetica;
 height:1500px;
 background-color:#F3F781;
}
#wrapper
{
 text-align:center;
 margin:0 auto;
 padding:0px;
 width:995px;
}
#scroll
{
 position:fixed;
 left:40%;
 top:30%;
 width:100px;
 height:35px;
 border:1px solid #868A08;
 background:none;
 color:#868A08;
 font-size:16px;
}
#stop_scroll
{
 position:fixed;
 left:50%;
 top:30%;
 width:100px;
 height:35px;
 border:1px solid #868A08;
 background:none;
 color:#868A08;
 font-size:16px;
}
.scroll_text
{
 width:500px;
 border:1px solid #868A08;
 margin-left:235px;
 margin-top:180px;
 padding:10px;
 color: #868A08;
 font-size: 15px;
 line-height: 1.5em;
 word-spacing: 6px;
}
</style>
</head>
<body>
<div id="wrapper">

<div id="scroll_div">
 <input type="button" id="scroll" value="Scroll" onclick="page_scroll();">
 <input type="button" id="stop_scroll" value="Stop Scroll" onclick="stop_scroll();">
 <div class="scroll_text">
  This is a demo of Auto Scrolling Page Using jQuery On TalkersCode.com 
  This is a demo of Auto Scrolling Page Using jQuery On TalkersCode.com
 </div>
</div>

</div>
</body>
</html>

In this step we create two buttons one for scroll the page automatically and other is used to stop the scrolling of the page. We add jquery.js file to scroll the page and we also create two functions page_scroll() and stop_scroll().

page_scroll() function is used to scroll the page using jquery animate() function and in stop_scroll() function we simply stop the scrolling when user don't want to auto scroll the page.You may also like page scroll to top using jQuery.

Thats all, this is how to auto scroll the page using jQuery. You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.

I hope this tutorial on auto scroll jquery helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Riya

A recent graduate with a Bachelor of Technology (B.Tech) in Computer Science from India. She is passionate about leveraging technology to solve real-world problems. With a strong foundation and experience in programming languages such as Python, Django, HTML, CSS, and JavaScript, java, php and have honed her skills through hands-on projects and coursework.

Follow Riya On Linkedin 🡪