Creating a dynamic scrollTop feature using a Jquery button in HTML

Recently, I created a website using WordPress and encountered an issue with implementing a scrolling arrow on the page. The current setup only allows the arrow to scroll down once, whereas I need it to navigate through the entire page smoothly. Here is the code snippet in question:

<script type="text/javascript">
  $(document).ready(function(){
    $('.ir-abajo').click(function(){
      $('body, html').animate({
        scrollTop: '220px'
      }, 200);
    });
  });
</script>

Answer №1

It seems like I understand your issue. To solve it, you just have to incorporate the existing scroll top value and then add the additional amount you want to scroll by. The previous success was due to the scroll top being at 0 and then being set to 220. However, in subsequent attempts, you were simply setting it back to 220 each time. You can try this revised code:

$(document).ready(function(){
  $('.ir-abajo').click(function(){
    var newScrollTop = ($(document).scrollTop() + 220) + 'px';
    $('body, html').animate({
      scrollTop: newScrollTop
    }, 200);
  });
});

Here's a fiddle link for demonstration: https://jsfiddle.net/tk9oxfpe/

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

The validation function in jQuery form does not seem to function properly when implemented within tabs on a webpage

Currently, I have successfully implemented a POST form with validation using the Validate library from jquery. However, an issue arises when integrating the tabs function from bootstrap and other libraries to organize the form into multiple tabs. The pro ...

On the application's user interface, the contact list from a mobile device

I have successfully integrated the Contacts native plugin from Ionic 3 into my app. While it is functioning properly, I am facing an issue with implementing it within the app's UI. Currently, the contact list loads outside the app and only returns to ...

"Track the progress of a form submission with a loading indicator using Sweet

I am looking to incorporate a waiting time animation when submitting a form, and I prefer using SweetAlert over a traditional loading image. Here is the basic code snippet: $("form").submit(function (e) { e.preventDefault(); // prevents def ...

Listening to audio on a mobile browser using an HTML audio element

What is the solution for the problem of playing audio on a mobile browser when it plays on a desktop browser but not on mobile? The code being used is: var audio = new Audio('sound.mp4') audio.play() ...

Tips for obtaining HTML content from a webpage through ajax?

I'm working on an AJAX request and facing a specific issue: function grabContent(url) { $.ajax({ url: url, error: function() { console.log('Error occurred'); ...

Adjusting SVG size based on the position of the cursor for transforming origin

My goal is to scale an SVG circle using the trackpad (by moving two fingers up and down), with the origin of the transform being the cursor position. Initially, the scaling works as intended, but on subsequent attempts, the circle changes position, which s ...

Issues with cascading style sheet navigation designs

Working on this project is new to me and I am encountering a challenge with two issues. My goal is to create a menu display similar to the image shown here: https://i.sstatic.net/FsHq5.png The problem lies in my inability to underline the selected optio ...

Toggle hyperlink's URL

My website features a menu panel that appears using pure CSS with the identifier #nav. It is controlled by a simple button. <a id="nav-burger" href="#nav"> <span></span> <span></span> <span></span> ...

The addScript feature seems to be experiencing difficulties upon the initial website load

Currently, I am utilizing the jquery.flexslider plugin and it is performing well. However, I have a specific requirement where I do not want to load the plugin for screens that are smaller than 600px. After experimenting with various scripts, I have final ...

Transforming milliseconds into a specific date using jQuery and JavaScript

My mind tends to wander, but I'll try to keep this concise - In an effort to cure my boredom, I've embarked on creating a "shoutbox", and one aspect has me a bit perplexed. I am seeking to record the time when a message is submitted, ensuring th ...

The Bootstrap HTML code fails to display correctly after adding a button

After minimizing the page, I need to display some buttons but for some reason, the menu is not showing. How can I fix this? <div class="navbar navbar-inverse navbar-static-top"> <div class="container"> <a href="#" class="navb ...

Show the extracted data on the following web page once it has been cleaned

I am looking to connect a python file with an HTML page using Flask application. On the first page (upload.html), the user is required to select the job field and job title from two dropdown menus. Afterwards, the user needs to upload a file containing a l ...

The laggy response occurs when clicking following an ajax request

My sidebar is experiencing lag after an ajax call. Here is the code snippet: $(document).ready(function () { $.post("<?php echo $baseurl;?>/api-cart-top.php",{ unique: "<?php echo $unique;?>" }, function(data) { ...

Eliminating the unwanted line breaks that are automatically inserted when integrating JavaScript with HTML code

Hey everyone, I'm new to web development and could really use some assistance. I am currently working on a website that shows the weather forecast for the next four days, using SimpleWeather.js. In my JavaScript, I want to display the High & Low temp ...

In Firefox, the functionality of applying background-position-y to a label when it is immediately preceded by a checked input[type=radio]

CSS selector input[type=checkbox]:checked + label is not functioning properly in Firefox browser! label { display: block; font-family: 'Muli'; font-size: 14px; color: #666; vertical-align: top; background: url("https://s31.postimg. ...

JavaScript: Retrieve the following instance of a div element

Is it possible to create a single function that will only impact the next instance of a div with the class "hiddenDiv" in relation to the clicked link? For example: <p><a href="#" class="showDivLink">click to show/hide div</a></p> ...

Retrieve text content using jQuery from two different classes

HTML & jQuery Example <div class="box-a">1 <input type="button" value="Click Me" class="btn-click"> </div> <div class="box-a">2 <input type="button" value="Click Me" class="btn-click"> </div> jQuery Script $(".btn-cli ...

When TTF fonts are installed on the device, they take precedence over Google fonts

I have successfully implemented the Ubuntu font from Google Fonts on my website: <link href='http://fonts.googleapis.com/css?family=Ubuntu:300,400,300italic,400italic,500,500italic,700,700italic' rel='stylesheet' type='text/css ...

Troubleshooting issue with Ajax delete functionality in Laravel 5.2

I've encountered an issue while attempting to remove a record from my mysql database within a laravel application. The error message I'm receiving is TokenMismatchException, and I'm unsure of the cause. Any assistance would be greatly apprec ...

Help required in understanding the process of creating a basic game using HTML, CSS, and JavaScript

Seeking assistance with my homework assignment for an immersive Full Stack Development course. The task involves creating a game with two characters placed side by side in their own containers. I am struggling to implement an "Attack" button that decreas ...