Sprawdź, czy użytkownik przewijał na dół

Robię system paginacji (coś jak Facebook), w którym zawartość ładuje się, gdy użytkownik przewija się na dół. Wyobrażam sobie, że najlepszym sposobem, aby to zrobić, jest znalezienie, gdy użytkownik jest na dole strony i uruchomić zapytanie ajax załadować więcej postów.

Jedynym problemem jest to, że nie wiem, jak sprawdzić, czy użytkownik przewijał na dół strony za pomocą jQuery. Jakieś pomysły?

Muszę znaleźć sposób, aby sprawdzić, kiedy użytkownik przewija się na dół strona z jQuery.

Author: Thomas Orlita, 2010-10-09

27 answers

Użyj .scroll() event on window, like this:

$(window).scroll(function() {
   if($(window).scrollTop() + $(window).height() == $(document).height()) {
       alert("bottom!");
   }
});

Możesz go przetestować tutaj , to zajmuje górne przewinięcie okna, więc ile jest przewinięte w dół, dodaje wysokość widocznego okna i sprawdza, czy jest równa wysokości ogólnej zawartości (document). Jeśli chcesz zamiast tego sprawdzić, czy użytkownik znajduje się w pobliżu na dole, wyglądałoby to mniej więcej tak:

$(window).scroll(function() {
   if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
       alert("near bottom!");
   }
});

Możesz przetestować tę wersję tutaj , po prostu dostosuj ją 100 do dowolnego piksela od dołu chcesz uruchomić.

 1062
Author: Nick Craver,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-10-09 22:39:11

Nie jestem do końca pewien, dlaczego to jeszcze nie zostało opublikowane, ale zgodnie z dokumentacją z MDN, najprostszym sposobem jest użycie natywnych właściwości javascript:

element.scrollHeight - element.scrollTop === element.clientHeight

Zwraca true, gdy znajdujesz się na dole dowolnego przewijalnego elementu. Więc po prostu używając javascript:

element.addEventListener('scroll', function(event)
{
    var element = event.target;
    if (element.scrollHeight - element.scrollTop === element.clientHeight)
    {
        console.log('scrolled');
    }
});

scrollHeight mają szerokie wsparcie w przeglądarkach, od ie 8, aby być bardziej precyzyjnym, podczas gdy clientHeight i scrollTop są obsługiwane przez wszystkich. Nawet ie 6. Powinno to być bezpieczne w przeglądarce.

 129
Author: Félix Gagnon-Grenier,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-12-31 18:13:35

Odpowiedź Nicka Cravera działa dobrze, oszczędź sobie problemu, że wartość $(document).height() różni się w zależności od przeglądarki.

Aby działać na wszystkich przeglądarkach, użyj tej funkcji z James Padolsey :

function getDocHeight() {
    var D = document;
    return Math.max(
        D.body.scrollHeight, D.documentElement.scrollHeight,
        D.body.offsetHeight, D.documentElement.offsetHeight,
        D.body.clientHeight, D.documentElement.clientHeight
    );
}

Zamiast $(document).height(), tak aby końcowy kod brzmiał:

$(window).scroll(function() {
       if($(window).scrollTop() + $(window).height() == getDocHeight()) {
           alert("bottom!");
       }
   });
 120
Author: Miles O'Keefe,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-05-08 22:39:37

Dla osób korzystających z rozwiązania Nicka i otrzymujących powtarzające się alerty / zdarzenia, można dodać wiersz kodu powyżej przykładu alertu:

$(window).scroll(function() {
   if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
       $(window).unbind('scroll');
       alert("near bottom!");
   }
});

Oznacza to, że kod będzie uruchamiany tylko wtedy, gdy po raz pierwszy znajdziesz się w odległości 100px od dolnej części dokumentu. Nie powtórzy się, jeśli przewiniesz do góry, a następnie z powrotem w dół, co może, ale nie może być przydatne w zależności od tego, do czego używasz kodu Nicka.

 53
Author: Tim Carr,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-10-01 16:51:44

Kontynuując doskonałą akceptowaną odpowiedź od Nicka Cravera, możesz zdławić Zdarzenie scroll tak, aby nie było uruchamiane tak często, dzięki czemu zwiększając wydajność przeglądarki :

var _throttleTimer = null;
var _throttleDelay = 100;
var $window = $(window);
var $document = $(document);

$document.ready(function () {

    $window
        .off('scroll', ScrollHandler)
        .on('scroll', ScrollHandler);

});

function ScrollHandler(e) {
    //throttle event:
    clearTimeout(_throttleTimer);
    _throttleTimer = setTimeout(function () {
        console.log('scroll');

        //do work
        if ($window.scrollTop() + $window.height() > $document.height() - 100) {
            alert("near bottom!");
        }

    }, _throttleDelay);
}
 40
Author: George Filippakos,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-19 07:11:14

Odpowiedź Nicka Cravera musi być nieco zmodyfikowana, aby działać na iOS 6 Safari Mobile i powinna brzmieć:

$(window).scroll(function() {
   if($(window).scrollTop() + window.innerHeight == $(document).height()) {
       alert("bottom!");
   }
});

Zmiana $(okno).wysokość() na okno.innerHeight należy to zrobić, ponieważ gdy pasek adresu jest ukryty, dodatkowe 60px są dodawane do wysokości okna, ale użycie $(window).height() nie odzwierciedla , a nie odzwierciedla tę zmianę, podczas gdy użycie window.innerHeight tak.

Uwaga : właściwość window.innerHeight obejmuje również poziomy pasek przewijania wysokość (jeśli jest renderowana), w przeciwieństwie do $(window).height(), która nie zawiera wysokości poziomego paska przewijania. Nie jest to problem w mobilnej Safari, ale może spowodować nieoczekiwane zachowanie w innych przeglądarkach lub przyszłych wersjach mobilnej Safari. Zmiana == na >= może naprawić to dla większości typowych przypadków użycia.

Przeczytaj więcej o window.innerHeight nieruchomości tutaj

 37
Author: BlueYoshi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-03-06 16:53:41

Oto dość proste podejście

const didScrollToBottom = elm.scrollTop + elm.clientHeight == elm.scrollHeight

Przykład

elm.onscroll = function() {
    if(elm.scrollTop + elm.clientHeight == elm.scrollHeight) {
        // User has scrolled to the bottom of the element
    }
}

Gdzie elm jest elementem pobranym z TJ document.getElementById.

 25
Author: Frederik Witte,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-04-15 12:31:48

Oto fragment kodu, który pomoże Ci debugować kod, przetestowałem powyższe odpowiedzi i stwierdziłem, że są wadliwe. Mam przetestować następujące NA Chrome, IE, Firefox, IPad (Safari). Nie mam żadnych innych zainstalowanych do testowania...

<script type="text/javascript">
   $(function() {
      $(window).scroll(function () {
         var docElement = $(document)[0].documentElement;
         var winElement = $(window)[0];

         if ((docElement.scrollHeight - winElement.innerHeight) == winElement.pageYOffset) {
            alert('bottom');
         }
      });
   });
</script>

Może być prostsze rozwiązanie, ale zatrzymałem się w momencie, w którym zadziałało

Jeśli nadal masz problemy z jakąś nieuczciwą przeglądarką, oto kod, który pomoże Ci debugować:

<script type="text/javascript">
   $(function() {
      $(window).scroll(function () {
         var docElement = $(document)[0].documentElement;
         var details = "";
         details += '<b>Document</b><br />';
         details += 'clientHeight:' + docElement.clientHeight + '<br />';
         details += 'clientTop:' + docElement.clientTop + '<br />';
         details += 'offsetHeight:' + docElement.offsetHeight + '<br />';
         details += 'offsetParent:' + (docElement.offsetParent == null) + '<br />';
         details += 'scrollHeight:' + docElement.scrollHeight + '<br />';
         details += 'scrollTop:' + docElement.scrollTop + '<br />';

         var winElement = $(window)[0];
         details += '<b>Window</b><br />';
         details += 'innerHeight:' + winElement.innerHeight + '<br />';
         details += 'outerHeight:' + winElement.outerHeight + '<br />';
         details += 'pageYOffset:' + winElement.pageYOffset + '<br />';
         details += 'screenTop:' + winElement.screenTop + '<br />';
         details += 'screenY:' + winElement.screenY + '<br />';
         details += 'scrollY:' + winElement.scrollY + '<br />';

         details += '<b>End of page</b><br />';
         details += 'Test:' + (docElement.scrollHeight - winElement.innerHeight) + '=' + winElement.pageYOffset + '<br />';
         details += 'End of Page? ';
         if ((docElement.scrollHeight - winElement.innerHeight) == winElement.pageYOffset) {
             details += 'YES';
         } else {
             details += 'NO';
         }

         $('#test').html(details);
      });
   });
</script>
<div id="test" style="position: fixed; left:0; top: 0; z-index: 9999; background-color: #FFFFFF;">

Mam nadzieję, że to kogoś uratuje czas.

 17
Author: Talon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-01-05 18:56:31

Proszę sprawdzić tę odpowiedź

 window.onscroll = function(ev) {
    if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
       console.log("bottom");
    }
};

Możesz zrobić footerHeight - document.body.offsetHeight, aby sprawdzić, czy jesteś w pobliżu stopki lub dotarłeś do stopki

 16
Author: Junaid Qadir Shekhanzai,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:18:21

To moje dwa grosze:

$('#container_element').scroll( function(){
        console.log($(this).scrollTop()+' + '+ $(this).height()+' = '+ ($(this).scrollTop() + $(this).height())   +' _ '+ $(this)[0].scrollHeight  );
        if($(this).scrollTop() + $(this).height() == $(this)[0].scrollHeight){
            console.log('bottom found');
        }
    });
 11
Author: ddanone,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-11-25 01:22:11
var elemScrolPosition = elem.scrollHeight - elem.scrollTop - elem.clientHeight;

Oblicza odległość paska przewijania do dołu elementu. Równe 0, jeśli pasek przewijania osiągnął dno.

 11
Author: Vasyl Gutnyk,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-11-12 22:13:12

Pure JS with cross-browser and debouncing (całkiem dobra wydajność )

var CheckIfScrollBottom = debouncer(function() {
    if(getDocHeight() == getScrollXY()[1] + window.innerHeight) {
       console.log('Bottom!');
    }
},500);

document.addEventListener('scroll',CheckIfScrollBottom);

function debouncer(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}
function getScrollXY(){var a=0,b=0;return"number"==typeof window.pageYOffset?(b=window.pageYOffset,a=window.pageXOffset):document.body&&(document.body.scrollLeft||document.body.scrollTop)?(b=document.body.scrollTop,a=document.body.scrollLeft):document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)&&(b=document.documentElement.scrollTop,a=document.documentElement.scrollLeft),[a,b]}
function getDocHeight(){var a=document;return Math.max(a.body.scrollHeight,a.documentElement.scrollHeight,a.body.offsetHeight,a.documentElement.offsetHeight,a.body.clientHeight,a.documentElement.clientHeight)}

Demo : http://jsbin.com/geherovena/edit?js, output

PS: Debouncer, getScrollXY, getDocHeight nie napisane przeze mnie

po prostu pokazuję, jak to działa i jak to zrobię

 6
Author: l2aelba,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-02-01 08:35:41

Moje rozwiązanie w prostym js:

let el=document.getElementById('el');
el.addEventListener('scroll', function(e) {
    if (this.scrollHeight - this.scrollTop - this.clientHeight<=0) {
        alert('Bottom');
    }
});
#el{
  width:400px;
  height:100px;
  overflow-y:scroll;
}
<div id="el">
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
</div>
 6
Author: Bakos Bence,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2019-05-23 07:01:17

Spróbuj użyć warunku dopasowania, jeśli przewiń do dolnego końca

if ($(this)[0].scrollHeight - $(this).scrollTop() == 
    $(this).outerHeight()) {

    //code for your custom logic

}
 4
Author: Hiren Patel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-11-01 14:35:24

Nick odpowiada dobrze, ale będziesz miał funkcje, które powtarzają się podczas przewijania lub w ogóle nie będą działać, jeśli użytkownik ma powiększone okno. Wymyśliłem łatwą poprawkę tylko z matematyki.okrągły pierwszej wysokości i działa tak, jak zakładano.

    if (Math.round($(window).scrollTop()) + $(window).innerHeight() == $(document).height()){
    loadPagination();
    $(".go-up").css("display","block").show("slow");
}
 3
Author: Florin Andrei,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-03-18 16:27:02

Możesz wypróbować następujący kod,

$("#dashboard-scroll").scroll(function(){
    var ele = document.getElementById('dashboard-scroll');
    if(ele.scrollHeight - ele.scrollTop === ele.clientHeight){
       console.log('at the bottom of the scroll');
    }
});
 3
Author: Shahrukh Anwar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-07-06 05:06:49

Zamiast nasłuchiwać zdarzenia scroll, za pomocą Intersection Observer {[5] } jest niedrogi do sprawdzenia, czy ostatni element był widoczny na viewporcie (oznacza to, że użytkownik został przewinięty na dół). Obsługuje również IE7 z polyfill .

var observer = new IntersectionObserver(function(entries){
   if(entries[0].isIntersecting === true)
      console.log("Scrolled to the bottom");
   else
      console.log("Not on the bottom");
}, {
   root:document.querySelector('#scrollContainer'),
   threshold:1 // Trigger only when whole element was visible
});

observer.observe(document.querySelector('#scrollContainer').lastElementChild);
#scrollContainer{
  height: 100px;
  overflow: hidden scroll;
}
<div id="scrollContainer">
  <div>Item 1</div>
  <div>Item 2</div>
  <div>Item 3</div>
  <div>Item 4</div>
  <div>Item 5</div>
  <div>Item 6</div>
  <div>Item 7</div>
  <div>Item 8</div>
  <div>Item 9</div>
  <div>Item 10</div>
</div>
 3
Author: StefansArya,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-02-26 10:47:48

Daje to dokładne wyniki podczas sprawdzania przewijalnego elementu (tzn. nie window):

// `element` is a native JS HTMLElement
if ( element.scrollTop == (element.scrollHeight - element.offsetHeight) )
    // Element scrolled to bottom

offsetHeight Należy podać rzeczywistą widoczną Wysokość elementu (w tym padding, margin, i paski przewijania), a scrollHeightto Cała Wysokość elementu, w tym niewidoczne (przepełnione) obszary.

jQuery's .outerHeight() powinno dać podobny wynik do JS .offsetHeight -- dokumentacja w MDN dla offsetHeight jest niejasna co do jego obsługi między przeglądarkami. Na cover more options, this is more complete:

var offsetHeight = ( container.offsetHeight ? container.offsetHeight : $(container).outerHeight() );
if  ( container.scrollTop == (container.scrollHeight - offsetHeight) ) {
   // scrolled to bottom
}

 2
Author: Yuval A.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2019-02-28 23:10:39

Wszystkie te rozwiązania nie działają dla mnie na Firefoksie i Chrome, więc używam niestandardowych funkcji z Miles O ' Keefe i meder omuralev tak:

function getDocHeight()
{
    var D = document;
    return Math.max(
        D.body.scrollHeight, D.documentElement.scrollHeight,
        D.body.offsetHeight, D.documentElement.offsetHeight,
        D.body.clientHeight, D.documentElement.clientHeight
    );
}

function getWindowSize()
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth, myHeight];
}

$(window).scroll(function()
{
    if($(window).scrollTop() + getWindowSize()[1] == getDocHeight())
    {
        alert("bottom!");
    }
});
 1
Author: hayj,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-01-29 17:39:25

Oto moje dwa grosze, ponieważ zaakceptowana odpowiedź nie zadziałała na mnie.

var documentAtBottom = (document.documentElement.scrollTop + window.innerHeight) >= document.documentElement.scrollHeight;
 1
Author: Razor,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-12-18 11:16:12

Wiele innych rozwiązań nie działa na mnie, ponieważ na przewijaniu do dołu mój div wyzwalał alert 2 razy, a przy przesuwaniu w górę również wyzwalał do kilku pikseli, więc rozwiązaniem jest:

        $('#your-div').on('resize scroll', function()
        {
            if ($(this).scrollTop() +
                $(this).innerHeight() >=
                $(this)[0].scrollHeight + 10) {

                alert('reached bottom!');
            }
        });
 1
Author: MR_AMDEV,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-08-17 21:16:19

Pozwól mi pokazać approch bez JQuery. Prosta funkcja JS:

function isVisible(elem) {
  var coords = elem.getBoundingClientRect();
  var topVisible = coords.top > 0 && coords.top < 0;
  var bottomVisible = coords.bottom < shift && coords.bottom > 0;
  return topVisible || bottomVisible;
}

Krótki przykład użycia:

var img = document.getElementById("pic1");
    if (isVisible(img)) { img.style.opacity = "1.00";  }
 0
Author: Alexei Zababurin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-10-24 15:08:33

Użyłem @ ddanone answear i dodałem wywołanie Ajax.

$('#mydiv').on('scroll', function(){
  function infiniScroll(this);
});

function infiniScroll(mydiv){
console.log($(mydiv).scrollTop()+' + '+ $(mydiv).height()+' = '+ ($(mydiv).scrollTop() + $(mydiv).height())   +' _ '+ $(mydiv)[0].scrollHeight  );

if($(mydiv).scrollTop() + $(mydiv).height() == $(mydiv)[0].scrollHeight){
    console.log('bottom found');
    if(!$.active){ //if there is no ajax call active ( last ajax call waiting for results ) do again my ajax call
        myAjaxCall();
    }
}

}

 0
Author: Henrique C.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-01-19 14:43:21

Aby zatrzymać powtarzający się alert o odpowiedzi Nicka

ScrollActivate();

function ScrollActivate() {
    $(window).on("scroll", function () {
        if ($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
            $(window).off("scroll");
            alert("near bottom!");
        }
    });
}
 0
Author: Arun Prasad E S,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-02-08 07:38:49

Google Chrome podaje pełną wysokość strony, jeśli wywołasz $(window).height()

Zamiast tego użyj window.innerHeight, Aby pobrać wysokość okna. Konieczne sprawdzenie powinno być:

if($(window).scrollTop() + window.innerHeight > $(document).height() - 50) {
    console.log("reached bottom!");
}
 0
Author: alierdogan7,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2019-08-14 04:51:04

Widocznie u mnie działało "ciało" a nie "okno" w ten sposób:

$('body').scroll(function() {


 if($('body').scrollTop() + $('body').height() == $(document).height()) {
     //alert at buttom
 }
 });

Dla kompatybilności między przeglądarkami:

  function getheight(){
    var doc = document;
    return  Math.max(
        doc.body.scrollHeight, doc.documentElement.scrollHeight,
        doc.body.offsetHeight, doc.documentElement.offsetHeight,
        doc.body.clientHeight, doc.documentElement.clientHeight

        );
   }

A następnie zamiast $(document).height() wywołanie funkcji getheight ()

$('body').scroll(function() {


   if($('body').scrollTop() + $('body').height() == getheight()  ) {
     //alert at bottom
 }
});

Do użytku w pobliżu dna:

$('body').scroll(function() {


if($('body').scrollTop() + $('body').height() > getheight() -100 ) {
    //alert near bottom
 }
 });
 0
Author: GeniusGeek,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-05-23 08:57:06

Użyłem tego testu, aby wykryć zwój dotarł do dołu: event.target.scrollTop === event.target.scrollHeight - event.target.offsetHeight

 0
Author: Zerzeri Mohamed,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-11-06 08:25:51