Получение оповещения в конце на div - PullRequest
0 голосов
/ 28 мая 2018

Я хочу вызвать окно оповещения, когда достигну конца div

Справка по https://stackoverflow.com/a/44100583/876739 и

var app = angular.module('test', []);
app.controller('MyCtrl', function($scope) {
  angular.element(document.querySelector('.test')).bind('scroll', function(){
     console.log('in scroll'+this.scrollTop +' '+this.offsetHeight+' '+this.scrollHeight);
      if (this.scrollTop + this.offsetHeight > this.scrollHeight) { //at the bottom
   alert("at bottom");
  }
   });

});
.test{
  overflow-y: scroll; height:100px; 
  background: yellow;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.9/angular.js"></script>
<body ng-app="test" ng-controller="MyCtrl">

<div class="test">
 Photography is the science, art, application and practice of creating durable images by recording light or other electromagnetic radiation, either electronically by means of an image sensor, or chemically by means of a light-sensitive material such as photographic film.[1]

Typically, a lens is used to focus the light reflected or emitted from objects into a real image on the light-sensitive surface inside a camera during a timed exposure. With an electronic image sensor, this produces an electrical charge at each pixel, which is electronically processed and stored in a digital image file for subsequent display or processing. The result with photographic emulsion is an invisible latent image, which is later chemically "developed" into a visible image, either negative or positive depending on the purpose of the photographic material and the method of processing. A negative image on film is traditionally used to photographically create a positive image on a paper base, known as a print, either by using an enlarger or by contact printing.

Photography is employed in many fields of science, manufacturing (e.g., photolithography), and business, as well as its more direct uses for art, film and video production, recreational purposes, hobby, and mass communication
</div>
</body>

Как этого добиться?

Ответы [ 3 ]

0 голосов
/ 28 мая 2018

эта проблема исправлена.если вы посмотрите на if, то наберете >, но если вы никогда не достигнете значения, превышающего значение, которое вам нужно сделать >= больше равного

var app = angular.module('test', []);
app.controller('MyCtrl', function($scope) {
  angular.element(document.querySelector('.test')).bind('scroll', function(){
     console.log('in scroll'+this.scrollTop +' '+this.offsetHeight+' '+this.scrollHeight);
      if (this.scrollTop + this.offsetHeight >= this.scrollHeight) { //at the bottom
   alert("at bottom");
  }
   });

});
.test{
  overflow-y: scroll; height:100px; 
  background: yellow;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.9/angular.js"></script>
<body ng-app="test" ng-controller="MyCtrl">

<div class="test">
 Photography is the science, art, application and practice of creating durable images by recording light or other electromagnetic radiation, either electronically by means of an image sensor, or chemically by means of a light-sensitive material such as photographic film.[1]

Typically, a lens is used to focus the light reflected or emitted from objects into a real image on the light-sensitive surface inside a camera during a timed exposure. With an electronic image sensor, this produces an electrical charge at each pixel, which is electronically processed and stored in a digital image file for subsequent display or processing. The result with photographic emulsion is an invisible latent image, which is later chemically "developed" into a visible image, either negative or positive depending on the purpose of the photographic material and the method of processing. A negative image on film is traditionally used to photographically create a positive image on a paper base, known as a print, either by using an enlarger or by contact printing.

Photography is employed in many fields of science, manufacturing (e.g., photolithography), and business, as well as its more direct uses for art, film and video production, recreational purposes, hobby, and mass communication
</div>
</body>
0 голосов
/ 28 мая 2018

Примените проверку на большее, чем равно this.scrollTop + this.offsetHeight >= this.scrollHeight, это будет работать.

0 голосов
/ 28 мая 2018

Тебе нужен равный, не превосходящий: D

var app = angular.module('test', []);
app.controller('MyCtrl', function($scope) {
  angular.element(document.querySelector('.test')).bind('scroll', function(){
     console.log('in scroll');
      if (this.scrollTop + this.offsetHeight == this.scrollHeight) { //at the bottom
   alert("at bottom");
  }
   });

});
.test{
  overflow-y: scroll; height:100px; 
  background: yellow;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.9/angular.js"></script>
<body ng-app="test" ng-controller="MyCtrl">

<div class="test">
 Photography is the science, art, application and practice of creating durable images by recording light or other electromagnetic radiation, either electronically by means of an image sensor, or chemically by means of a light-sensitive material such as photographic film.[1]

Typically, a lens is used to focus the light reflected or emitted from objects into a real image on the light-sensitive surface inside a camera during a timed exposure. With an electronic image sensor, this produces an electrical charge at each pixel, which is electronically processed and stored in a digital image file for subsequent display or processing. The result with photographic emulsion is an invisible latent image, which is later chemically "developed" into a visible image, either negative or positive depending on the purpose of the photographic material and the method of processing. A negative image on film is traditionally used to photographically create a positive image on a paper base, known as a print, either by using an enlarger or by contact printing.

Photography is employed in many fields of science, manufacturing (e.g., photolithography), and business, as well as its more direct uses for art, film and video production, recreational purposes, hobby, and mass communication
</div>
</body>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...