How can I animate scrolling up or down using jQuery and CSS?

I have a a element that triggers an action when clicked:

<a href="#" class="hel" onclick="YPCP1_();">Scroll down</a>

Also,

function YPCP_(){
    var scroll = $(window).scrollTop();
    window.scrollTo(0, 600);
}

The function successfully scrolls down to position 600. However, it currently jumps directly to position 600, but I would like it to slide down instead. For example,

slide down and reach position 600 in 6 seconds
.

I hope this explanation is clear. Thank you in advance! ( '_' )

Answer №1

If you're seeking the jQuery method for smooth animations (http://api.jquery.com/animate/), look no further.

To specify the final scrollTop position and duration of the animation, try something like this:

$('.content').animate({
    scrollTop: "+=" + 600
  }, 6000);

A demonstration of this concept can be found in this fiddle: https://jsfiddle.net/L6uuve70/10/

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

Clicking 'Submit' triggers a continuous loop upon loading

I set up this form to automatically submit once the page has finished loading. However, I seem to be encountering a problem where the page gets stuck in a continuous loop of reloading. HTML <body onload="document.getElementById('filters').su ...

Encountering a TypeError indicating that the asterisk is not functioning as a proper function

Whenever I run my server.js file, an error keeps popping up: TypeError: routing is not a function This occurs in the following line of code: routing(app); In my routing.js file, the content looks like this: // JavaScript source code var friends = requ ...

Ways to align text in a table row in a way that it remains positioned at the center of the screen's visible area

Can anyone assist me with this task? I need help centering text within a table row ('Some text here...') so that it always appears in the middle of the screen. The table will have horizontal scrolling. .compare-content { max-width: 480px; ...

Sending an HTML form data to a Node.js server

I'm currently working on a simple project that involves creating a web form and sending it to node.js in order to save the information received. I've been following some YouTube tutorials (https://www.youtube.com/watch?v=rin7gb9kdpk), but I' ...

Eliminate the dark backdrop from html5 videos that only shows up for a brief moment

Is there a way to remove the brief black background that appears when loading an HTML5 video? I have tried using CSS without success. The HTML: <div id="start-screen"> <video id="video-element"> <source src="video-mp4.mp4" type="vide ...

How to ensure onmouseenter and onmouseleave work properly in Chrome using HTML, JavaScript, and jQuery

<div style="position: relative; left: 50px; top: 30px; width: 300px; height: 150px; background: #222222;" onmouseenter="this.style.background='#aaaaaa'" onmouseleave="this.style.background='#222222';"></div> http://jsfiddle ...

rearrange results in ng-repeat based on specified array in AngularJS

Currently delving into Angularjs and have a quick query: I recently received an array from a user which looks like this: userPreferences = [7,5,4] Additionally, I am working with an object that uses ng-repeat to showcase various news items. The object s ...

Using the Ruby on Rails link_to tag along with a mouseenter jQuery function allows for dynamic

How can I make an image display in a div when the mouse hovers over a link_to using Rails? The code below seems to work, but I'm unsure of how it functions. <a href="#" class="nav-link roll"> <%= image_tag("chair1.jpg") %>Chesterfield Cha ...

Techniques to dynamically insert database entries into my table using ajax

After acquiring the necessary information, I find myself faced with an empty table named categorytable. In order for the code below to function properly, I need to populate records in categoryList. What should I include in categoryList to retrieve data fro ...

MUI: Autocomplete cannot accept the provided value as it is invalid. There are no matching options for the input `""`

https://i.stack.imgur.com/KoQxk.png Whenever I input a value in the autocomplete component, an unresolved warning pops up... Here's how my input setup looks: <Autocomplete id="cboAdresse" sx={{ width: 100 + " ...

Using Jquery for a Second Timer

I have a jQuery function that looks like the one below. The result is displayed in a span, but when the page is reloaded, this span briefly disappears and then reappears. Is there a way to prevent this from happening? I need it to stay visible at all tim ...

Retrieve the labels associated with highlighted text in a JTextPane

Hey everyone! I'm currently working with a JTextPane that has content type 'text/html'. I have loaded the Bible into this JTextPane where verses are separated by tags. What I want to achieve is determining the selected verse when a user clic ...

The MUI date picker does not display dates earlier than 1900

I am in need of a datepicker that allows users to select dates from the 1850s, however, the mui datepicker only starts from the 1900s. To demonstrate this issue, I have provided a sample code in this codesandbox I am utilizing mui in the remainder of my ...

Having trouble getting my soundboard to work properly on mobile devices

I recently created a soundboard using HTML5, CSS3, and JavaScript. While the audio plays back perfectly on my computer when I click the buttons, I encounter an issue when trying to use it on a smartphone. <!DOCTYPE html> <html lang="en"> <h ...

Angular.js reports that the custom HTTP response header is missing

Despite Chrome showing the correct POST response headers, my custom HTTP header X-Auth-Token is returning null in the callback function for the POST request. Angular.js seems to only be returning Cache-Control and Content-Type, with everything else showing ...

Obtain an image from CSS using :after with jQuery

In my attempt to create a button animation where checkboxes in the .focus state should display their assigned background: url("x.svg"); from the CSS file, I have encountered an issue with my markup. I am struggling to make the :after element appear on the ...

Display or conceal fields depending on custom object specifications

I am attempting to centralize my show/hide functionality for fields in one object (like vm.foo) that contains key-value pairs. For example, I could add another pair like 1502: true to hide a field with the key 1502. Is there a way to pass variables from t ...

Tips for retrieving the primary key of the highlighted row in bs_grid

I've integrated bs_grid to showcase a lineup of company names, each associated with a unique GUID identifier. Here's how I've set up the grid: $(function() { $('#grid1').bs_grid({ ajaxFetchDataURL: 'CompaniesList.asmx/G ...

What is the best way to determine if a date is empty using Vuetify?

Could someone help me with checking if a date was entered by the user? I want to display an error message if a date is not provided. I attempted to use a rule for this purpose, but unfortunately it's not showing any error message. Below is the code I ...

Looking for the quickest hash and salt method for IP addresses in Node.JS?

Currently, there are many stipulations regarding the tracking of user data such as unique visits and returning users. An issue arises in certain regions where IP addresses are considered sensitive personal information. To continue identifying unique user ...