5

I have django project and I can't make jquery script to run in google chrome.

Simple code for checking if scroll is at bottom:

 <script language="JavaScript" type="text/JavaScript">
    window.onload = function () {

       $('#scrolling').on('scroll', chk_scroll);
    };

    function chk_scroll(e) {

        var elem = $(e.currentTarget);
        if (elem[0].scrollHeight - elem.scrollTop() == elem.outerHeight()) {
           alert("bottom")
        }
    }
</script>

It works in Opera, Explorer, Firefox, Chrome (As single html file, not part of project), jsfiddle.

P.s jquery loads correctly and other scripts works.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
Victoria
  • 51
  • 1
  • 1
    Have you tried using [`$( document ).ready()`](https://learn.jquery.com/using-jquery-core/document-ready/) instead of `window.onload` once. – palaѕн Apr 01 '20 at 13:42
  • Yes, same result, as setTImeout – Victoria Apr 01 '20 at 13:43
  • 2
    I don't necessarily think it is the issue, but the values in your language and type attributes are camelcased, when they should be lowercased. Better yet, for normal script tags those can be left off. – Taplar Apr 01 '20 at 14:14
  • 1
    Could this be any help? https://stackoverflow.com/a/28287574/7867822 – Anurag Srivastava Apr 01 '20 at 15:05
  • Thanks for suggestions, learned new things and found problem. Anurag, your link really helped! It was in zooming browser with cntrl+scroll. My Chrome was zoomed by default to 105%, and this 5% was the problem.I simply need to count resizing – Victoria Apr 02 '20 at 06:48

1 Answers1

0

Try the following:

$( window ).on( 'scroll', checkScroll );


function checkScroll()
{
    const documentScrollTop     = $( document ).scrollTop();
    const documentOuterHeight   = $( document ).outerHeight();
    const windowOuterHeight     = $( window ).outerHeight();

    if ( documentScrollTop >= documentOuterHeight - windowOuterHeight )
    {
        //bottom
    }
}

you don't need to use any element but the window to check if you've hit bottom

stefantigro
  • 452
  • 2
  • 12