HTML steps for smooth scrolling to the top and bottom of a list

My HTML contains a vertical list with top and bottom arrows positioned nearby. I am looking to implement a function where clicking on the top arrow will move the list up gradually, and clicking on the bottom arrow will move the list down step by step. Below is the HTML code along with the Angular script for reference.

<div class="verticalCarousel">
<a ng-click="scrolltoBottom();" class="scroll-to-bottom">BOTTOM</a>
<ul class="nav nav-tabs  verticalCarouselGroup" role="tablist" id="messagestab" >
        <li role="presentation">
            TEST
        </li>
        <li role="presentation">
            TEST
        </li>
        <li role="presentation">
            TEST
        </li>
        <li role="presentation">
            TEST
        </li>

        <li role="presentation">
            TEST
        </li>

        <li role="presentation">
            TEST
        </li>
  </ul>

  <a ng-click="scrolltoTop();" class="scroll-to-top">TOP</a>
</div>

Below is the Angular code snippet that achieves the desired functionality.

var i = 1;
    $scope.scrolltoBottom = function(){
        var list = $(".verticalCarouselGroup");
        var container = $(".verticalCarousel");
        console.log(list.height()-list.offset().top+"= BOTTOM OF CARO")
        console.log(container.height()-container.offset().top+"= BOTTOM OF container")

        i = i+50;
        list.css({
            'position': 'relative',
            'top':i ,
        }); 
    };

    $scope.scrolltoTop = function(){
        var list = $(".verticalCarouselGroup");
        var container = $(".verticalCarousel");
        console.log(list.height()-list.offset().top+"= BOTTOM OF CARO")
        console.log(container.height()-container.offset().top+"= BOTTOM OF container")

        i = i-50;
        list.css({
            'position': 'relative',
            'top':i ,
        });         

    };

I have also included a link to a jsfiddle demonstration.

https://jsfiddle.net/arunkumarthekkoot/863z3kky/2/

Answer №1

Try this out for a similar effect: Interactive Example

angular.module("exampleApp", []).controller('ScrollController', ['$scope', function($scope) {
  $scope.scrollDown = function() {
    var elements = $(".verticalCarouselGroup");
    elements.animate({ "marginTop": "+=50px" }, "slow");
  };

  $scope.scrollUp = function() {
    var elements = $(".verticalCarouselGroup");
    elements.animate({ "marginTop": "-=50px" }, "slow");
  };
}]);

If you want to prevent scrolling beyond certain points, you can implement checks for the top and bottom.

Tip: Compare the top and bottom values with the current margin-top: (elements.css('marginTop'))

Answer №2

It seems like you want to achieve a scroll down effect on li elements one by one by clicking on an arrow?

If that's the case: You could consider using a smooth scroll plugin like ui.kit and then trigger a click event using setTimeout or setInterval that scrolls down to each element based on an array like

myListEl = ['#first', '#second', etc...];

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 Click Event is failing to trigger for a dynamically created ID within a span element

I am currently working on a Task Project. In this project, I have been adding items dynamically and generating items dynamically as well. However, when it comes to deleting items by clicking on a span element, the click event doesn't seem to work. I ...

What is the best way to invoke a controller function from within a directive's link function using '&' and passing a parameter?

Trying to pass a parameter into a function within a directive link function has been a bit challenging. I've come across questions and examples like this one on Stack Overflow, as well as blog posts such as What IBroke. While I've seen paramete ...

The selection option fails to update when there is a change in the ng-model

My issue involves two select tags, named Select 1 and Select 2, each with their own ng-model variables and separate methods triggered by ng-change. I am attempting to set the value of the Select 1 option from a method called by the ng-change of Select 2. H ...

PHP - attempted to restrict file size, only to receive a warning: The POST Content-Length surpasses the designated limit

Recently, I decided to experiment with the file upload functionality on my website. The upload file code allows users to either select a file for upload or submit it without any attachment. Initially, I implemented an error message that restricts the file ...

The XML string in ajax data is consistently coming back as empty

Whenever I send an xml data string to the server side, it always registers as empty, causing issues. Here is a snippet of my code: $(document).on('click','#metadataListTable .delete', function () { / var ans = confirm("Do ...

Enhance phonegap functionality by incorporating jQuery autocomplete for extensive result sets

I am looking to implement autocomplete functionality for an input field in my phonegap app. My plan is to utilize the autocomplete widget provided by jQuery and have it search for strings based on queries from a SQLite database installed on my tablet. $(" ...

Converting a ReadStream to a ReadableStream in NodeJS: A Step-by-Step Guide

This question poses the opposite scenario to converting a ReadableStream into a ReadStream. ReadStream is a data structure utilized in Node.js ReadableStream is a structure that comes from the web platform, as detailed here As new runtimes like Deno or t ...

Display a JSX component based on a specific condition

As a newcomer to React, I am currently working on the navigation portion of my Navbar.js using the react-router-dom useLocation hook. I have successfully obtained the active path that leads to views and now I want to display custom text when a user reaches ...

Each column has its own scroll bar, making use of 100% of the available space within a container that is 100%

I am attempting to create 3 columns, each with its own scroll bar, while also taking up 100% of the available space. However, I am facing issues where there is either no scroll bar present or the columns are not occupying 100% of the available space. It ...

Controlling dropdown menus filled with AJAX responseData

When it comes to Javascript, JQuery has always been a reliable companion for me. However, there are instances where I encounter challenges that require some extra effort to overcome. Today happens to be one of those days. I've stumbled upon an issue t ...

Sorting through items based on their characteristics, not just their numerical properties

I have JSON objects displayed on the page using ng-repeat. While I am able to search through them, I also need to be able to 'filter' them based on a specific parameter using a select HTML element. For better clarity, let's consider the fol ...

Can I rely on setTimeout to guarantee the execution of a task in NodeJS?

I am working on a REST backend using ExpressJS. One of the functionalities of this backend is to allow users to upload file assets, but these files should only exist for 10 minutes. Is it secure to rely on setTimeout to automatically delete the uploaded f ...

Is there a way for me to instruct jQuery to revert an element back to its initial value, prior to any dynamic alterations?

My question is regarding changing the content of a div using the `html()` method in JavaScript. I am currently working on implementing a "cancel" button and would like to revert the content back to its original value without having to completely reset it w ...

Issue: Unhandled promise rejection: BraintreeError: The 'authorization' parameter is mandatory for creating a client

I'm currently working on integrating Braintree using Angular with asp.net core. However, I've encountered an issue that I can't seem to solve. I'm following this article. The version of Angular I'm using is 14, and I have replicate ...

Node.js and Express: tackling the problem of duplicate variables

I have a checkUser middleware that saves the user information when a JWT is verified. However, when I integrate it into my routes and attempt to log res.locals.user.username, the username appears twice in the console. This duplication is causing issues wit ...

The hamburger icon is not visible on smaller screens when using the Bootstrap 5 navbar

'The stylesheets for Bootstrap CSS and JS have been included in the file. The content shows up fine with default colors, but not when I customize them.' ''' <li class="nav-item"> <a class= ...

Combining CSS and HTML with IE10

With the release of Windows8 and IE10 as developer previews, I am curious about what features IE10 does not support that IE9/8 did, as well as what new features it now supports. Thank you for your assistance! ...

What is the best way to avoid having identical entries in a row when using jQuery's multiple select feature?

I am facing the challenge of working with multiple rows containing select boxes that have similar content. Each row has several select boxes and each item in a row can only be used once due to specific classifications assigned to each column. I want the se ...

Alternating the tooltip icon based on the field's condition

Looking for a way to create a tooltip for an input field that involves changing icons based on certain conditions. An example scenario is the password field in a registration form. Seeking advice on the best approach to achieve this. Currently, here' ...

Can I Intercept POST Array with JQuery before Sending it?

Can I capture the POST Array with JQuery before sending the form? I'm aware of using preventDefault() to access all variables, but that's not my desired approach. I need to retrieve the POST Array prior to sending it via AJAX to a php file. ...