How to Achieve Seamless Vertical Scrolling Through Clicking a Button

I'm currently working with Bootstrap 4 Modal and have removed the Overflow-Y (ScrollBar) to enhance the design. However, I've also incorporated a function with two buttons (Up & Down) using JavaScript to facilitate easier navigation for users. The issue is that these buttons do not automatically scroll; instead, the user has to manually click multiple times to navigate up and down, which is not ideal.

That's why I am looking to implement a feature similar to the default Up & Down scroll buttons found in browsers, where continuous scrolling occurs when a user holds down the button for an extended period.

Please refer to the GIF image for a better visual understanding and provide feedback as it would greatly benefit me. Thank you.

var buttonDown = document.getElementById('btnDown');
             var buttonUp = document.getElementById('btnUp');

             buttonDown.onclick = function () {
               document.getElementById('mo-body').scrollTop += 40;
             };
             buttonUp.onclick = function () {
               document.getElementById('mo-body').scrollTop -= 40;
             };

The relevant CSS code:

.modal-body::-webkit-scrollbar {
   display: none;
}


.modal-body P {
 color: red;
}

... (CSS Code Continued)

Your HTML code section:

(HTML Code Section)
https://i.sstatic.net/3Lx7b.gif

Answer №1

Implement the following code:

html {
    scroll-behavior: smooth;
}

Answer №2

Perhaps something along these lines.

var buttonDown = document.getElementById('btnDown');
                  var buttonUp = document.getElementById('btnUp');

                  buttonDown.onclick = function () {
                    document.getElementById('mo-body').scrollTop += 40;
                      $("body, html").css("scroll-behavior", "smooth");
                  };
                  
                
                  
                  buttonUp.onclick = function () {
                    document.getElementById('mo-body').scrollTop -= 40;
                       $("body, html").css("scroll-behavior", "smooth")
                  };
.modal-body::-webkit-scrollbar {
    display: none;
}


.modal-body P {
  color: red;
}

.modal.left_modal .modal-dialog {
  position: fixed;
  margin: auto;
  
...

</div>

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

Tips for creating a scale animation using HTML5 Canvas

I am currently developing a canvas whiteboard tool and I have reached the stage where I am focusing on implementing the Zoom In and Zoom Out feature. While the functionality is working fine, I would like to enhance it with smooth animations for scaling. H ...

Shaky xy positions while mapping a vector to NDC

Exploring ThreeJS has been an intriguing experience for me, especially when projecting vectors in the world space onto normalized device coordinates (NDC). Surprisingly, everything works flawlessly without any hiccups. However, a noticeable issue arises w ...

Receive an error stating "Filename is not defined" when attempting to upload an image in React

Postman functioning properly with my backend code. I utilized form-data and added a random file. The file uploaded successfully to the image folder, but a problem arises when it comes to React. It fails to upload and displays an error on the backend stati ...

Setting up vue-resource root and authentication configuration

Currently, I am reviewing the documentation for vue-resource that outlines how to configure it: https://github.com/vuejs/vue-resource/blob/master/docs/config.md The documentation specifies setting headers with a common authorization value: Vue.http.hea ...

Encountering issues with app functionality following update to Ionic RC4 version

Since upgrading from Ionic rc3 to rc4, I've been facing difficulties running my app smoothly. The app compiles without any errors when I use ionic-app-scripts build --prod, but when I try to run it on my iPhone, all I get is a blank screen and an err ...

Setting up the CSS loader in a Vue.js project using webpack

I am currently working on a new vue-cli project and have successfully installed the Pure.CSS framework using npm install purecss --save. However, I am struggling to seamlessly integrate, import, or load the css framework into my project. I am unsure of whe ...

Troubleshooting CSS Issues in ASP.NET Boilerplate

I am attempting to apply a CSS style to a text input similar to the one found on the CreateUser default page. However, I am encountering an issue where the blue line under the textbox does not appear when I navigate away from and then return to the page. ...

How can we achieve the same functionality as React Native's { flex: 1 } in React JS?

I've been diving into React Native development, and now I'm exploring React.js for web applications. However, I'm facing a challenge in creating a simple View that takes up the entire screen to begin experimenting with different components. ...

One of three hidden divs suddenly appears on the screen when a button is clicked, standing out from the rest

Currently, I have 3 divs set up: var t1 = document.getElementById("tafel1"); var t2 = document.getElementById("tafel2"); var t3 = document.getElementById("tafel3"); function tafel1() { if (t1.style.display === "none") { ...

Responsive Design and the Importance of Setting Min-Width in Bootstrap 3

After doing some research on Stack Overflow about defining a minimum width for a responsive layout in Bootstrap3, I encountered conflicting answers related to "media queries." My goal is to make my layout responsive up to a certain point. Once it reaches, ...

Updating code to insert elements into an array/data structure using Javascript

Hey everyone, I'm new to Javascript and I'm trying to make a change to some existing code. Instead of just returning the count of elements, I want to add each of the specified elements to an array or list. Here is the original code from a Seleni ...

Disable ESLint's "no-undef" rule for a specific folder when using Jest

Currently, I am using jest for testing my api calls. In addition, I utilize eslint to validate my test codes. However, since jest does not require explicit definition of methods such as test() or expect(), when running eslint, I encounter errors like: ...

Designing websites using elements that float to the right in a responsive manner

Responsive design often uses percentage width and absolute positioning to adjust to different screen sizes on various devices. What if we explore the use of the float right CSS style, which is not as commonly used but offers high cross-browser compatibilit ...

How can a list of objects in a JPA entity with a many-to-one relation to a data entity be sorted based on the result of a method call from the data entity?

In my JPA entity User, there is a OneToMany relation to a UserStats entity. I made changes to the code to use UserStats instead of storing victoryRatio directly in the User entity. Now, calculateVictoryRatio() method is implemented in the UserDetails entit ...

Encountering an Unexpected Token Import Issue with Page Objects in Webdriver.io and Node.js

Hi, I've encountered an issue while attempting to run my test scripts using Node.JS and Webdriver.io. Everything was functioning correctly until I decided to implement the Page Object Pattern. I am now receiving an error in the console output: ERROR: ...

Identifying the moment an external swf file has finished loading

My JavaScript code is responsible for loading external swf files by adding the "object" and "embed" tags after the page has finished loading. I am looking for a way to detect when the swf file has been fully loaded so that I can handle this event appropr ...

Ways to initiate the download of an audio link using JS without the need for the browser to redirect to a different page

I am looking to create a script that can automatically download audio files from a website. The problem I'm encountering is that using element.click() to simulate a "click" event doesn't work as expected, as the browser ends up navigating to the ...

Discovering details regarding cookies established by an external domain

Is it possible to retrieve the host address of the domain that created a cookie on my webpage? Here is the scenario I am facing: I am on "domain A" and have a script linked from "domain B". A method on "domain B" sets a cookie on my "domain A". How can ...

What are the differences between a Django/React app API when in production versus during development?

Recently, I created a React app that relies on Axios for fetching APIs. During the development phase, I noticed an issue with the API URL configuration. Since my ReactApp was hosted on localhost:3000 but making API calls to 127.0.0.1 - I encountered some e ...

How can I ensure an element is consistently centered within another element using Bootstrap 3?

I'm currently facing an issue with aligning elements in my center navigation. While keeping the navigation centered is not a problem, I'm struggling with positioning another element to the right of it. This element needs to be displayed in an acc ...