javascript - Infinite-scroll keeps loading everything even if scroll-bar is not moved -
i'm trying use infinite scroll, , works not way want it. when open page loads infinitely. want load 15 picture when open page , load 15 more when scroll bottom increasing url's "index".
angular.module('home', ['infinite-scroll']) .controller('anasayfa', ['$scope', '$http', function ($scope, $http, $location) { $scope.method = 'get'; var index = 0; $scope.url = 'http://api.donanimhaber.com/api/v1/site/newssite?pageindex=' + index + '&pagesize=15'; $scope.loadcompleted = true; $scope.loadmore = function () { if (index > 0) { if ($scope.loadcompleted == false) return; $scope.loadcompleted = false; $http({ method: $scope.method, url: $scope.url }). then(function (response) { $scope.status = response.status; (var = 0; < response.data.data.length; i++) { $scope.data.push(response.data.data[i]); } index++; $scope.loadcompleted = true; }, function (response) { $scope.data = response.data || "request failed"; $scope.status = response.status; }); } }; $scope.code = null; $scope.response = null; $http({ method: $scope.method, url: $scope.url }). then(function (response) { $scope.status = response.status; $scope.data = response.data.data; index++; }, function (response) { $scope.data = response.data || "request failed"; $scope.status = response.status; }); }]);
how can fix this? thanks.
//index.cshtml
@{ layout = null; } <!doctype html> <html ng-app="home"> <head> <meta charset="utf-8" /> <title>home</title> </head> <body ng-controller="anasayfa"> <div infinite-scroll="loadmore()" infinite-scroll-distance="0" ng-view auto-scroll> <div class="home" ng-repeat="d in data"> <div class="news"> <p class="topic">{{d.title}}</p> <a href="/detay{{d.url}}"><img class="image" src="{{d.image}}" /></a> </div> </div> </div> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script> <script src="https://code.jquery.com/jquery-3.0.0.min.js" type="text/javascript"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/nginfinitescroll/1.2.2/ng-infinite-scroll.min.js"></script> <link href="~/content/site.css" rel="stylesheet" /> <script src="/scripts/haberler.js"></script> </body> </html>
Comments
Post a Comment