The AngularJS ngInfiniteScroll feature continues to trigger even as I scroll upwards

When I scroll upwards, it triggers my infiniteSubjects() function. However, I only want it to trigger while scrolling downward. I've searched through various posts but haven't found a solution yet. I've tried using the infinite-scroll-disabled attribute and even inserting a 1003px height <div> at different places at the bottom to occupy space. Unfortunately, none of these attempts have worked.

<div ng-app="mainApp" ng-controller="gridController" class="container">
    <div class="row" infinite-scroll="infiniteSubjects()" infinite-scroll-distance="0" >
        <div ng-repeat="subject in (filteredSubjects = (allSubjects | orderBy:subjectOrder | limitTo:subjectLimit))">

            <div class="col-md-2 subject-card">
                {{ subject.name }}
             ..more divs go here..
            </div>
        </div>
    <div style="clear:both; height:1003px;"> </div>
    </div>
</div>

In my controller:

$scope.infiniteSubjects = function() {
    console.log("scrolling");
    $scope.subjectLimit += 1;
};

I also checked the ng-infinite-scroll.js file to monitor the heights while scrolling by adding some console.logs

windowBottom = $window.height() + $window.scrollTop();
console.log("WINDOWBOTTOM " + windowBottom);

elementBottom = elem.offset().top + elem.height();
console.log("ELEMENT BOTTOM" + elementBottom);

remaining = elementBottom - windowBottom;
console.log("REMAINING" + remaining);

Upon page load:

WINDOWBOTTOM 1194
ELEMENT BOTTOM 1194
REMAINING 0

The fact that window bottom and element bottom are initially the same is puzzling. Why is this happening?

While scrolling down, the value of remaining decreases by 100. Conversely, when scrolling up, it increases by 100, although it never becomes positive since the initial value is 0.

Answer №1

While researching on SO, I stumbled upon someone else's response in a related thread: ngInfiniteScroll - loadMore() method gets called on every mouse-scroll

All it took was adding <!DOCTYPE html> to the top of my html code.

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

Break up a line within an ionic element by inserting a linebreak tag

Currently, I am constructing an app using ionic framework and facing a challenge in inserting a linebreak within an ionic tag to ensure proper display inside the designated container... <h2>{{caravan.model}}</h2> ...

Relocating the output of JavaScript to a different location

I'm currently facing an issue with transferring my JavaScript output (start) from the black box to the grey box. I am unsure about what needs to be included in the functions (moveRight and moveLeft) for the transition to occur smoothly. Even after re ...

How can I generate spheres in threejs with varying radii while all passing through the shared point located at coordinates (0,0,200)?

Is there a way to generate spheres in threejs where the radius increases while always passing through a single point at 0,0,200? This would allow the origin of each new sphere to move along the z-axis. Appreciate any help, AriemWebgl ...

Error message: Unable to locate module without the '.js' extension at the end of the import file path

It seems like the solution is not difficult, just something obvious. I am working on a simple TypeScript project. There are no modules involved, only TypeScript for compilation. The TS files compile into JS files in the dist folder, which are then connect ...

Utilize Python and Selenium to interact with AngularJS dropdown lists for non-select elements

Currently, I am leveraging Selenium to extract information from this website. Upon clicking a button on the page, a dropdown list appears, and my goal is to be able to select different values from this list using my program. Having conducted extensive res ...

Arranging objects in JavaScript arrays

There is an array containing elements with two properties each: const players = [{id: 15, score: 567}, {id: 4, score: 789}, {id: 27, score: 123}, {id: 1, score: 654}]; The task at hand is to sort the a ...

What is the best way to adjust the dimensions of an image in a Chrome application?

var xhr = new XMLHttpRequest(); xhr.open('GET', 'https://unique-domain-not-csp-friendly.com/image.png',true); xhr.responseType = 'blob'; xhr.onload = function(e) { var img = document.createElement('img'); img.src = w ...

Internet Explorer 11 encountering a syntax error with SweetAlert2

I have implemented the following code from the SweetAlert2 examples page: swal({ title: 'Are you sure?', text: "You won't be able to revert this!", type: 'warning', showCancelButton: true, confirmButtonColor: '#3085 ...

Using configuration files to specify extensions for Nodemon to watch

Is there a more efficient way to specify a watch list using configuration files instead of the command line? The documentation for nodemon explains the command-line method: https://github.com/remy/nodemon#nodemon I tried using a nodemon.json configurati ...

How can we extract validation data from a function using Ajax and then transfer that information to another Ajax query?

I have an AJAX function that validates a textbox on my page. After validating, I need to perform an action with that value (search in the database and display results in the textbox). However, I also need the validation function for another separate functi ...

When attempting to submit information to a database table, I encounter an error in the browser console: "Uncaught (in promise) Error: Request failed with status code 404."

In my React Node project's login page, I am encountering the following issue. Despite thoroughly reviewing my code after each execution, the error persists. My goal is to pass data from the login page into my MySQL database; this marks the initial sta ...

How can I generate a list of JavaScript files to be included in a template for both production and development environments using Grunt?

I need a way to organize a list of JavaScript files in one central location, either within gruntfile.js or an external JSON file, and then dynamically implement it into a template for both development and production environments. List of JavaScript files: ...

Is there a way to prevent the DOM from loading images until Angular has successfully injected the correct variables?

Having some trouble with this block of code I have: <div class="image" ng-repeat="image in images"> <img src="{{image.url}}"></img> </div> It seems that the image sources are being set correctly, but I keep getting an error wh ...

The Ashima Perlin noise shader seems to be malfunctioning on newer releases of Three.JS

Seeking help on SO as a final attempt to resolve an issue with the latest Three.JS, as my Google searches have turned up empty. I am working with the Ashima Perlin noise shader (examples here) - Everything runs smoothly with version 48 of Three.JS, but w ...

Developing a nested JSON structure

I'm struggling with a seemingly simple task of creating a JSON object. Despite my efforts, I can't seem to find the right information to guide me through it. Here is what I have so far: var myJsonObject = new Object(); myJsonObject.context.appli ...

Is there a way to efficiently update the CSS class attribute for all list items using just pure JavaScript?

I am looking to use pure Javascript, not jQuery, to access all elements within a <ul> list and remove the active class from every item except for the one selected in my menu. Shown below is the list: <ul id='flash-menu'> <li id=" ...

Reading the fixture JSON file in Cypress - A step-by-step guide

I'm struggling to read data from a JSON fixture file in Cypress for my test cases. Despite following various instructions and examples, I can't seem to make it work. Any ideas on what I might be doing wrong? Below are the details of my files alo ...

Translating SQL to Sequelize Syntax

I have an SQL query that I need to rewrite as a sequelize.js query in node.js. SELECT historyTable1.* FROM table1 historyTable1 WHERE NOT EXISTS ( SELECT * FROM table1 historyTable2 WHERE historyTable2.id=historyTable1.id AND historyTable2.da ...

Conversation panel text slipping out of <div>

I am currently working on creating a mock "chat" feature. The issue I am facing is that when I repeatedly click the "send" button, the text overflows from the div. Is there a way to prevent this by stopping the text near the border of the div or adding a s ...

Trouble with the query waypoints extension in a simple demonstration

Can anyone help me figure out why the basic example from the waypoints plugin isn't working for me? Here's a link to the jsfiddle I created: http://jsfiddle.net/ZA8bd/2/ CSS .block1 { margin-top:30px; width: 400px; background: red; ...