Gradually move down until you reach 100%

When I attempt to click a button and scroll, I can easily achieve this with HTML (option 1). However, the scrolling motion is abrupt and I would prefer to have more control over the speed of the scroll.

I then experimented with jQuery (Option1) but I am unsure how to instruct it to scroll 100% of the window and adjust the speed. Is there a way to accomplish this using CSS and/or jQuery?

Option 1. Scroll with HTML:
http://jsfiddle.net/VPT4q/

<div id="first">
    <a href="#second">
        <div id="down"></div>
    </a>
</div>

<div id="second"></div>

Option 2. Scroll with jQuery: http://jsfiddle.net/VPT4q/1/

$(function(){      
    $('#down').click(function() {
        // window.scrollBy(0,200);
        window.scrollTo(0,200);
    });
})

Answer №1

$('#scroll-down').on('click', function() {
      $('html, body').animate({ scrollTop: $('body').height() }, 1000);
});

//The value of 1000 represents the duration in milliseconds for the scroll animation

Answer №2

When utilizing jQuery, it is recommended to implement it in the following manner:

$('#down').click(function() {
    $('html,body').animate({scrollTop: $('#second').offset().top},'slow');
});

You can test out the functionality on this fiddle: http://jsfiddle.net/pJgYT/

This may not be the exact solution you are looking for, but it should serve as a good starting point.

If you want to adjust the scrolling speed, simply modify the duration from 'slow' to a specific number value like '1000'.

$('html,body').animate({scrollTop: $('#second').offset().top}, 2000);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a popup dialog form using ASP.NET and jQuery within an ASP:FormView control

I'm currently facing an issue where I am utilizing a jQuery popup dialog with an asp:FormView. The purpose of this popup is to allow the user to input a hyperlink, which is then placed in a textbox control within the FormView. The popup dialog div i ...

What is the best way to identify the complete template of an Angular component's CSS without mentioning any specific tags?

Typically, I structure each view with an outer DIV that serves as the foundational background. <div class="outer"> <!-- Content goes in here --> </div> Then, within my SASS file, I apply styles to it like this. div.outer { ... } Thi ...

Activate radio button exclusively for admin user

My current application includes an admin panel with functions to manage users. I use a while loop in the form creation to display 3 user types: Admin, Manager, and User, which are pulled from a database. Admin Manager User This is how my HTML Form look ...

Aligning the icon within the div and adding a gap between each div

I'm fairly new to web design, specifically dealing with html and css, and I'm attempting to create something similar to the design in the following image: https://i.sstatic.net/Dy5F3.png My struggle lies in centering the fa-envelope-o icon both ...

Exploring the process of implementing Tailwind CSS with esbuild

My journey to understand bundlers and plugins has led me to create a workflow using esbuild, tailwindcss, react, typescript, and more. However, I'm struggling to connect tailwind css to eslint and other tools. According to the tailwind css docs, I nee ...

Is there anyone who can provide insight on replicating the hover effect showcased on this webpage?

Is there a way to replicate the hover effect seen on the images of this page - ? When you hover over an image, a larger picture appears within a bordered window. Any suggestions on how to achieve this effect would be greatly appreciated! ...

Step-by-step guide on constructing a table using jQuery datatables featuring row child functionality

I have implemented jQuery datatable with Ajax. The server running Laravel returns a JSON in the following format: { "draw":0, "recordsTotal":201 ,"recordsFiltered":201, "data":[{ "id":"1", "numsocio":"1", "identificacion":"9999999999", "nombre":"Anna, "a ...

Navigating the sizing differences between iMacs and standard laptops with Bootstrap

Currently, I am working on creating an admin dashboard. At the office, I use an iMac with a resolution of 2,500px x 1,5000~, while at home I work on a laptop with a resolution of 1366 x 768. The issue I am facing is that both resolutions fall under the XL ...

What is an alternative method for loading values without using setTimeout?

Consider the example code below: <select id="connection" onchange="load_databases_of_this_connection();"></select> <select id="database" onchange="load_tables_of_this_database();"></select> <select id="table" onchange="load_colu ...

Unraveling an AJAX response in JSON format using jQuery

I am a beginner in the world of Jquery and Ajax. I've crafted the code below to automatically populate a form with data after selecting an option from a combo box within a form, using guidance from this helpful post Autopopulate form based on selected ...

CSS: The enigma of :nth-child - what eludes my understanding?

I have 2 divs which are similar to 2 td's in a table. My goal is to have 2 red divs, followed by 2 blue divs and so on. However, my current code doesn't seem to be working. Can someone point out what I am missing: <style> .irow :nth-child( ...

Hover over the horizontal dropdown menu

I have attempted to create a horizontal drop down menu using this tutorial and demo I envision the menu to look like this: I want the sub-menu to appear to the right of the parent menu, as shown in this example The next step involves the sub-menus. The ...

managing json arrays within Laravel

I am currently working on a project where I am focusing on creating an ajax call and handling the data that comes back. Here is what my Ajax call looks like: $.ajax({ type: 'GET', dataType: "json", url: ****, ...

Choose an option from the dropdown list using ellipses

I am looking to truncate the dropdown list options with ellipsis, and when clicked on the ellipsis, users should be able to view the full option values. For instance, the dropdown list currently looks like this: <select id ="id"> <option ...

In IE11, the fixed position does not depend on the parent container

In Chrome and Firefox, when a transform is defined in the parent container, the child's position will inherit from the parent container. However, this behavior does not occur in IE. So, how can I ensure that it works in IE11 so that the child's ...

What is the best way to align two items where one is centered and the other is positioned to the left?

In an attempt to customize a chat call to action, I am looking to have an icon aligned to the left and some centered text. Here is an example of how I envision it: [ @ Text aligned in center ] Here is what I have tried so far: .icon{ justify-self: ...

Refreshing a div using Php and ajax at specific intervals

Can I load the div values automatically when the page loads along with after a time interval? How can I achieve this? <script type="text/javascript> $(document).ready(function() { setInterval(function(){ $("#Te ...

Do I need to include both the JavaScript and CSS CDN for the bootstrap CDN to work properly, or can I just use one of them?

Which resource should I use for my project? Should I go with CSS, JS, BUNDLE or all of them? https://i.sstatic.net/0Yi3F.png I am interested in using button styling, grid, card components (and possibly dropdowns in the future) https://cdn.jsdelivr.ne ...

Implementing interactive tables with XML data using jQuery

I have been attempting to generate table rows using data retrieved from an xml response. Below is my success function: success: function(response) { $('id', response).each(function() { const row = $('< ...

What could be the key factor that is causing my ajax post request to not receive a 200 response?

Seeking assistance with troubleshooting my ajax request. I suspected it was the _token causing issues, but even after including it, I'm still not receiving a 200 response. Maybe there's a parameter missing in my function? Below is the code snippe ...