document.body.scrollTop is always 0 in IE even when scrolling












60















I am displaying the value of document.body.scrollTop in the status bar while moving the mouse. The value is always 0 in IE. Why is always 0? Is there another way to get how much the scroll bar has moved?










share|improve this question























  • What DOCTYPE are you using?

    – Nick Craver
    Apr 26 '10 at 22:06






  • 3





    I upvoted the selected answer since no one else seemed to have done it ( unless there was a downvote to counter it ). It would have been nice if you had responded to Nick's question.

    – meder omuraliev
    Jul 29 '10 at 16:28
















60















I am displaying the value of document.body.scrollTop in the status bar while moving the mouse. The value is always 0 in IE. Why is always 0? Is there another way to get how much the scroll bar has moved?










share|improve this question























  • What DOCTYPE are you using?

    – Nick Craver
    Apr 26 '10 at 22:06






  • 3





    I upvoted the selected answer since no one else seemed to have done it ( unless there was a downvote to counter it ). It would have been nice if you had responded to Nick's question.

    – meder omuraliev
    Jul 29 '10 at 16:28














60












60








60


19






I am displaying the value of document.body.scrollTop in the status bar while moving the mouse. The value is always 0 in IE. Why is always 0? Is there another way to get how much the scroll bar has moved?










share|improve this question














I am displaying the value of document.body.scrollTop in the status bar while moving the mouse. The value is always 0 in IE. Why is always 0? Is there another way to get how much the scroll bar has moved?







html css






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 26 '10 at 22:04









Tony_HenrichTony_Henrich

16.7k55191317




16.7k55191317













  • What DOCTYPE are you using?

    – Nick Craver
    Apr 26 '10 at 22:06






  • 3





    I upvoted the selected answer since no one else seemed to have done it ( unless there was a downvote to counter it ). It would have been nice if you had responded to Nick's question.

    – meder omuraliev
    Jul 29 '10 at 16:28



















  • What DOCTYPE are you using?

    – Nick Craver
    Apr 26 '10 at 22:06






  • 3





    I upvoted the selected answer since no one else seemed to have done it ( unless there was a downvote to counter it ). It would have been nice if you had responded to Nick's question.

    – meder omuraliev
    Jul 29 '10 at 16:28

















What DOCTYPE are you using?

– Nick Craver
Apr 26 '10 at 22:06





What DOCTYPE are you using?

– Nick Craver
Apr 26 '10 at 22:06




3




3





I upvoted the selected answer since no one else seemed to have done it ( unless there was a downvote to counter it ). It would have been nice if you had responded to Nick's question.

– meder omuraliev
Jul 29 '10 at 16:28





I upvoted the selected answer since no one else seemed to have done it ( unless there was a downvote to counter it ). It would have been nice if you had responded to Nick's question.

– meder omuraliev
Jul 29 '10 at 16:28












3 Answers
3






active

oldest

votes


















115














You may want to try this for an older doctype in IE:



var top = (document.documentElement && document.documentElement.scrollTop) || 
document.body.scrollTop;





share|improve this answer


























  • Wouldn't that bomb if document.documentElement is undefined? I think you meant document.documentElement instead of document.documentElement.scrollTop in the first part of the ternary expression. :)

    – Vivin Paliath
    Apr 26 '10 at 22:11











  • @Vivin - It's not undefined, the scroll property just isn't set, resulting in 0/false.

    – Nick Craver
    Apr 26 '10 at 22:13






  • 2





    This can be abbreviated to var top = document.documentElement.scrollTop || document.body.scrollTop;

    – Web_Designer
    Apr 28 '12 at 0:49






  • 12





    You thought you could do a simple || operation? Chuck Testa. If you try to access the documentElement's property .scrollTop, it will blow. Best (read: non-explosive) solution: var top = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;

    – AlbertEngelB
    Aug 16 '12 at 3:33








  • 1





    Be careful using document.documentElement.scrollTop in iOS. It will always report 0. If you need to actually test for scrollTop==0 then this switch won't work.

    – Jason
    Feb 5 '14 at 2:39



















15














this function provides a cross-browser implementation of reading the scroll offset:



function posTop() {
return typeof window.pageYOffset != 'undefined' ? window.pageYOffset: document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop? document.body.scrollTop:0;
}





share|improve this answer


























  • Thanks, this is the only answer that works in both older versions of IE as newest version of Chrome.

    – Kamelkent
    Jun 24 '15 at 8:01



















10














Depending on the DOCTYPE, you would have to use document.body.scrollTop or document.documentElement.scrollTop. Have you tried the second one?



You can do something like this:



var scrollTop = document.documentElement ? document.documentElement.scrollTop :
document.body.scrollTop;


I ran into these links while researching your problem:





  • Window size and scrolling (towards the bottom)

  • document.body.scrollTop in IE


This may help you out a little more.






share|improve this answer


























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f2717252%2fdocument-body-scrolltop-is-always-0-in-ie-even-when-scrolling%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    115














    You may want to try this for an older doctype in IE:



    var top = (document.documentElement && document.documentElement.scrollTop) || 
    document.body.scrollTop;





    share|improve this answer


























    • Wouldn't that bomb if document.documentElement is undefined? I think you meant document.documentElement instead of document.documentElement.scrollTop in the first part of the ternary expression. :)

      – Vivin Paliath
      Apr 26 '10 at 22:11











    • @Vivin - It's not undefined, the scroll property just isn't set, resulting in 0/false.

      – Nick Craver
      Apr 26 '10 at 22:13






    • 2





      This can be abbreviated to var top = document.documentElement.scrollTop || document.body.scrollTop;

      – Web_Designer
      Apr 28 '12 at 0:49






    • 12





      You thought you could do a simple || operation? Chuck Testa. If you try to access the documentElement's property .scrollTop, it will blow. Best (read: non-explosive) solution: var top = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;

      – AlbertEngelB
      Aug 16 '12 at 3:33








    • 1





      Be careful using document.documentElement.scrollTop in iOS. It will always report 0. If you need to actually test for scrollTop==0 then this switch won't work.

      – Jason
      Feb 5 '14 at 2:39
















    115














    You may want to try this for an older doctype in IE:



    var top = (document.documentElement && document.documentElement.scrollTop) || 
    document.body.scrollTop;





    share|improve this answer


























    • Wouldn't that bomb if document.documentElement is undefined? I think you meant document.documentElement instead of document.documentElement.scrollTop in the first part of the ternary expression. :)

      – Vivin Paliath
      Apr 26 '10 at 22:11











    • @Vivin - It's not undefined, the scroll property just isn't set, resulting in 0/false.

      – Nick Craver
      Apr 26 '10 at 22:13






    • 2





      This can be abbreviated to var top = document.documentElement.scrollTop || document.body.scrollTop;

      – Web_Designer
      Apr 28 '12 at 0:49






    • 12





      You thought you could do a simple || operation? Chuck Testa. If you try to access the documentElement's property .scrollTop, it will blow. Best (read: non-explosive) solution: var top = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;

      – AlbertEngelB
      Aug 16 '12 at 3:33








    • 1





      Be careful using document.documentElement.scrollTop in iOS. It will always report 0. If you need to actually test for scrollTop==0 then this switch won't work.

      – Jason
      Feb 5 '14 at 2:39














    115












    115








    115







    You may want to try this for an older doctype in IE:



    var top = (document.documentElement && document.documentElement.scrollTop) || 
    document.body.scrollTop;





    share|improve this answer















    You may want to try this for an older doctype in IE:



    var top = (document.documentElement && document.documentElement.scrollTop) || 
    document.body.scrollTop;






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Aug 16 '12 at 3:40









    AlbertEngelB

    8,603115179




    8,603115179










    answered Apr 26 '10 at 22:09









    Nick CraverNick Craver

    538k11512041109




    538k11512041109













    • Wouldn't that bomb if document.documentElement is undefined? I think you meant document.documentElement instead of document.documentElement.scrollTop in the first part of the ternary expression. :)

      – Vivin Paliath
      Apr 26 '10 at 22:11











    • @Vivin - It's not undefined, the scroll property just isn't set, resulting in 0/false.

      – Nick Craver
      Apr 26 '10 at 22:13






    • 2





      This can be abbreviated to var top = document.documentElement.scrollTop || document.body.scrollTop;

      – Web_Designer
      Apr 28 '12 at 0:49






    • 12





      You thought you could do a simple || operation? Chuck Testa. If you try to access the documentElement's property .scrollTop, it will blow. Best (read: non-explosive) solution: var top = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;

      – AlbertEngelB
      Aug 16 '12 at 3:33








    • 1





      Be careful using document.documentElement.scrollTop in iOS. It will always report 0. If you need to actually test for scrollTop==0 then this switch won't work.

      – Jason
      Feb 5 '14 at 2:39



















    • Wouldn't that bomb if document.documentElement is undefined? I think you meant document.documentElement instead of document.documentElement.scrollTop in the first part of the ternary expression. :)

      – Vivin Paliath
      Apr 26 '10 at 22:11











    • @Vivin - It's not undefined, the scroll property just isn't set, resulting in 0/false.

      – Nick Craver
      Apr 26 '10 at 22:13






    • 2





      This can be abbreviated to var top = document.documentElement.scrollTop || document.body.scrollTop;

      – Web_Designer
      Apr 28 '12 at 0:49






    • 12





      You thought you could do a simple || operation? Chuck Testa. If you try to access the documentElement's property .scrollTop, it will blow. Best (read: non-explosive) solution: var top = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;

      – AlbertEngelB
      Aug 16 '12 at 3:33








    • 1





      Be careful using document.documentElement.scrollTop in iOS. It will always report 0. If you need to actually test for scrollTop==0 then this switch won't work.

      – Jason
      Feb 5 '14 at 2:39

















    Wouldn't that bomb if document.documentElement is undefined? I think you meant document.documentElement instead of document.documentElement.scrollTop in the first part of the ternary expression. :)

    – Vivin Paliath
    Apr 26 '10 at 22:11





    Wouldn't that bomb if document.documentElement is undefined? I think you meant document.documentElement instead of document.documentElement.scrollTop in the first part of the ternary expression. :)

    – Vivin Paliath
    Apr 26 '10 at 22:11













    @Vivin - It's not undefined, the scroll property just isn't set, resulting in 0/false.

    – Nick Craver
    Apr 26 '10 at 22:13





    @Vivin - It's not undefined, the scroll property just isn't set, resulting in 0/false.

    – Nick Craver
    Apr 26 '10 at 22:13




    2




    2





    This can be abbreviated to var top = document.documentElement.scrollTop || document.body.scrollTop;

    – Web_Designer
    Apr 28 '12 at 0:49





    This can be abbreviated to var top = document.documentElement.scrollTop || document.body.scrollTop;

    – Web_Designer
    Apr 28 '12 at 0:49




    12




    12





    You thought you could do a simple || operation? Chuck Testa. If you try to access the documentElement's property .scrollTop, it will blow. Best (read: non-explosive) solution: var top = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;

    – AlbertEngelB
    Aug 16 '12 at 3:33







    You thought you could do a simple || operation? Chuck Testa. If you try to access the documentElement's property .scrollTop, it will blow. Best (read: non-explosive) solution: var top = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;

    – AlbertEngelB
    Aug 16 '12 at 3:33






    1




    1





    Be careful using document.documentElement.scrollTop in iOS. It will always report 0. If you need to actually test for scrollTop==0 then this switch won't work.

    – Jason
    Feb 5 '14 at 2:39





    Be careful using document.documentElement.scrollTop in iOS. It will always report 0. If you need to actually test for scrollTop==0 then this switch won't work.

    – Jason
    Feb 5 '14 at 2:39













    15














    this function provides a cross-browser implementation of reading the scroll offset:



    function posTop() {
    return typeof window.pageYOffset != 'undefined' ? window.pageYOffset: document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop? document.body.scrollTop:0;
    }





    share|improve this answer


























    • Thanks, this is the only answer that works in both older versions of IE as newest version of Chrome.

      – Kamelkent
      Jun 24 '15 at 8:01
















    15














    this function provides a cross-browser implementation of reading the scroll offset:



    function posTop() {
    return typeof window.pageYOffset != 'undefined' ? window.pageYOffset: document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop? document.body.scrollTop:0;
    }





    share|improve this answer


























    • Thanks, this is the only answer that works in both older versions of IE as newest version of Chrome.

      – Kamelkent
      Jun 24 '15 at 8:01














    15












    15








    15







    this function provides a cross-browser implementation of reading the scroll offset:



    function posTop() {
    return typeof window.pageYOffset != 'undefined' ? window.pageYOffset: document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop? document.body.scrollTop:0;
    }





    share|improve this answer















    this function provides a cross-browser implementation of reading the scroll offset:



    function posTop() {
    return typeof window.pageYOffset != 'undefined' ? window.pageYOffset: document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop? document.body.scrollTop:0;
    }






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jun 19 '12 at 13:57

























    answered Jun 19 '12 at 13:40









    ijavidijavid

    501917




    501917













    • Thanks, this is the only answer that works in both older versions of IE as newest version of Chrome.

      – Kamelkent
      Jun 24 '15 at 8:01



















    • Thanks, this is the only answer that works in both older versions of IE as newest version of Chrome.

      – Kamelkent
      Jun 24 '15 at 8:01

















    Thanks, this is the only answer that works in both older versions of IE as newest version of Chrome.

    – Kamelkent
    Jun 24 '15 at 8:01





    Thanks, this is the only answer that works in both older versions of IE as newest version of Chrome.

    – Kamelkent
    Jun 24 '15 at 8:01











    10














    Depending on the DOCTYPE, you would have to use document.body.scrollTop or document.documentElement.scrollTop. Have you tried the second one?



    You can do something like this:



    var scrollTop = document.documentElement ? document.documentElement.scrollTop :
    document.body.scrollTop;


    I ran into these links while researching your problem:





    • Window size and scrolling (towards the bottom)

    • document.body.scrollTop in IE


    This may help you out a little more.






    share|improve this answer






























      10














      Depending on the DOCTYPE, you would have to use document.body.scrollTop or document.documentElement.scrollTop. Have you tried the second one?



      You can do something like this:



      var scrollTop = document.documentElement ? document.documentElement.scrollTop :
      document.body.scrollTop;


      I ran into these links while researching your problem:





      • Window size and scrolling (towards the bottom)

      • document.body.scrollTop in IE


      This may help you out a little more.






      share|improve this answer




























        10












        10








        10







        Depending on the DOCTYPE, you would have to use document.body.scrollTop or document.documentElement.scrollTop. Have you tried the second one?



        You can do something like this:



        var scrollTop = document.documentElement ? document.documentElement.scrollTop :
        document.body.scrollTop;


        I ran into these links while researching your problem:





        • Window size and scrolling (towards the bottom)

        • document.body.scrollTop in IE


        This may help you out a little more.






        share|improve this answer















        Depending on the DOCTYPE, you would have to use document.body.scrollTop or document.documentElement.scrollTop. Have you tried the second one?



        You can do something like this:



        var scrollTop = document.documentElement ? document.documentElement.scrollTop :
        document.body.scrollTop;


        I ran into these links while researching your problem:





        • Window size and scrolling (towards the bottom)

        • document.body.scrollTop in IE


        This may help you out a little more.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Apr 26 '10 at 22:17

























        answered Apr 26 '10 at 22:06









        Vivin PaliathVivin Paliath

        73.3k31180269




        73.3k31180269






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f2717252%2fdocument-body-scrolltop-is-always-0-in-ie-even-when-scrolling%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            Npm cannot find a required file even through it is in the searched directory

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith