Tips for navigating through elements generated with ng-repeat as I scroll

There is a list generated using ng-repeat along with two buttons for moving up or down. Users have the option to select any item from the list and utilize the buttons to navigate through it.

However, when I lower the selected item using the "go down" button, the scroll bar remains in a fixed position, causing the selected item to be out of view.

My goal is to automatically adjust the scroll position when the selected item is no longer visible.

Answer №1

        <div class="panel-body panelBodySelectedData" style="padding-left: 10px">
        <nav>
            <ul ng-repeat="item in resultJson.items" class="nav nav-pills nav-stacked span2">
                <li class="itemReporting" ng-click="selectItem($index)"  ng-class="{selectedReportingItem: $index==selectedIndex}" >{{item.label}}</li>
            </ul>
        </nav>
    </div>


$scope.goUp = function(){
    if($scope.selectedIndex > 0){
        console.log('goUp');
        $scope.aux = $scope.resultJson.items[$scope.selectedIndex];
        $scope.selectedIndex -- ;
        $scope.resultJson.items[$scope.selectedIndex+1] = $scope.resultJson.items[$scope.selectedIndex];
        $scope.resultJson.items[$scope.selectedIndex] = $scope.aux;
    }
};

$scope.goDown = function(){
    if($scope.selectedIndex < $scope.resultJson.items.length -1){
        console.log('goDown');
        $scope.aux = $scope.resultJson.items[$scope.selectedIndex];
        $scope.selectedIndex ++ ;
        $scope.resultJson.items[$scope.selectedIndex-1] = $scope.resultJson.items[$scope.selectedIndex];
        $scope.resultJson.items[$scope.selectedIndex] = $scope.aux;
        $location.hash('bottom');

          // call $anchorScroll()
          $anchorScroll();

    }
};

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 Managing Disconnection Issues in Angular 7

My goal is to display the ConnectionLost Component if the network is unavailable and the user attempts to navigate to the next page. However, if there is no network and the user does not take any action (doesn't navigate to the next page), then the c ...

Encasing distinct HTML text with a custom color palette

How can I create a specific color scheme for my HTML table's Status parameter, where the values can be SUCCESS, FAILURE, or IN PROGRESS? I'm utilizing Angular 4 (HTML and TypeScript) for this task. Any tips on how to achieve this? ...

The size attributes on <img> tags do not function as expected

I'm facing an issue with the following code: $("#myId").html( "<img src='" + $(xml).find("picture").text() + "' height="42" width="42"></img>" ); Everything works perfectly until I include the 'height="42" wid ...

Background image not adhering to the page width as expected within the Bootstrap framework

I feel like I'm losing my mind. Currently, I am in the process of designing a section that consists of four photo boxes - two at the top and two below. In order to achieve this layout, I have turned to utilizing Bootstrap. Unfortunately, this parti ...

Toggle Form Section Visibility

I am working on a table with five rows that have upload buttons. Each time I submit a row, the page refreshes, but I want to hide all but one row at a time. When the first submit button is clicked, it should show the next row and hide the previous ones. Th ...

Save to a JSON file

Hey there, I'm having some trouble with pushing a temporary value to a JSON file using the command "MyJSON.name.push". It keeps giving me an error saying "Undefined is not an object". I've tried different approaches and using JavaScript arrays wo ...

Decrease the gap between the ticks on a horizontal bar chart in ChartJS

Currently, I am utilizing the horizontal bar chart feature from chartjs and encountering an issue with the chart appearing too large. In addition, there is a notable gap between the ticks on the xAxis (as shown in the attached image). Does anyone know how ...

What is the best way to enable autocomplete in AngularJS?

I am working with an object that contains both a name and an ID. I want to implement autocomplete functionality based on the name property. Below is the code snippet that I have tried: //Js file var app=angular.module("myapp",[]); app.controller("controll ...

Saving fonts when deploying on Vercel with Next.js is not supported

Troubleshooting Differences in Local Viewing and Deployment: https://i.stack.imgur.com/jktPN.png When viewing locally, everything appears as expected. However, upon deploying, there are noticeable discrepancies. https://i.stack.imgur.com/NKQQ6.png Even ...

What is the proper way to delete a callback from a promise object created by $q.defer() in AngularJS?

When working with AngularJS, the $q.defer() promise object has the ability to receive multiple notify callbacks without overwriting previous ones. var def = $q.defer(); def.promise.then(null, null, callback1); def.promise.then(null, null, callback2); If ...

The Three JS on the website is error-free, yet it fails to function properly

I've been attempting to replicate the example three.js page on my own website, complete with a canvas for the 3D animation. However, I'm encountering an issue where nothing is displayed, despite no errors appearing. I've tried troubleshootin ...

What is preventing ColladaLoader.js in Three.js from loading my file?

Recently, I decided to experiment with three.js and wanted to load a .dae file called Raptor.dae that I obtained from Ark Survival Evolved. Despite having some web development knowledge, I encountered an issue when trying to display this particular file in ...

What factors dictate the color of rows in jquery datatable designs?

Within the jQuery datatable styles, such as "smoothness," the rows are displayed in different colors. What factors determine which colors are shown on each row? And is there a way to customize this color scheme? Refer to the example below from their sampl ...

Learn how to update a fixed value by adding the content entered into the Input textfield using Material-UI

I made a field using the Input component from material-ui: <Input placeholder="0.00" value={rate} onChange={event => { this.setState({ `obj.rate`, event.target.value }); }} /> Whenever I input a rate into this field, ...

Using jQuery to attach events and trigger them

Within my code, I have the following scenarios: $("#searchbar").trigger("onOptionsApplied"); And in another part of the code: $("#searchbar").bind("onOptionsApplied", function () { alert("fdafds"); }); Despite executing the bind() before the trigge ...

The elements with identical IDs are being superimposed

There are two div elements on my webpage, both assigned the "nav" class. Below is the CSS code: .nav { border-radius: 1em; background-color: #0000BB; color: white; padding: 1em; position: absolute;//Fits size to content. margin: 1em; left: 50%; ...

Exploring ways to connect my React application with a node backend on the local network?

On my MacBook, I developed a react app that I access at http://localhost:3000. In addition, I have a nodejs express mysql server running on http://localhost:5000. The issue arises when I try to open the IP address with port 3000 in the browser of my Window ...

Multi-object retrieval feature in Material Dialog

I am encountering an issue with Material Dialog when confirming the action to "remove row" in a table. Initially, removing from the dialog works fine and deletes a row. However, after closing the dialog and re-calling it for the second time, the removal ac ...

Enhance the functionality of the Angular Tabs directive

I have developed a tab directive in Angular using jQuery. Despite everything appearing correct, I am unable to identify any issues with it. Could someone please review my code and point out any mistakes? I believe my Angular directive relies too hea ...

Pass the DateTime object from ASP.NET to angularjs as a structured data type instead of converting it to a

I'm encountering an issue where I am sending a complex object from my ASP.NET backend to the AngularJS frontend. This object includes a DateTime property and a list of objects, each with their own DateTime property. These properties are all sent as st ...