$ (window). Height () document altitude issue

Source: Internet
Author: User

Encounter one of these problems:

There is a project to do well, the test step-by-step carefully, after a period of time, found that the previous completion of the function of a problem

First, describe the function that has the problem:

A method of searching the web for a scroll bar pull-down load

$ (window). Scroll (function() {      if(document). ScrollTop () >=$ (document). Height (  )-$ (window). Height ()) {  alert ("AA");     }}); 

When we have scrollbars, we can generate events by pulling the scrollbar down so that we can add the content of the Web page that needs to be loaded in the event, and many websites do this to save the pressure on the image server.

But today, doing something to find out that running on IE is normal, running on Google and Firefox is not normal. Because of the IE test has been used, so, do not know where the change will lead to this error, the error occurs as follows

The normal situation is

The event is triggered when the scroll bar is to the bottom, so I can load what I need because $ (document). ScrollTop () >=$ (document). Height ()-$ (window). Height () When the height of the scrollbar is greater than the height of the window-when the document is high, the event is triggered, and all you see is the effect shown!

However, the following error occurs:

This event will be triggered regardless of how the scroll bar moves.

These two values are printed in the following: found this $ (document). Height () and (window). Height () the values in Google and Firefox are the same, in IE, but also different, that is, no matter how the scroll bar moves, This judging condition is always set up, so there is nothing wrong with IE, other browsers appear incorrect situation.

Workaround:

If you've changed this just as much as I did, then that's the reason.

I changed it.

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

Changed it.

Finally, this problem is solved.

That is, $ (window). Height () The value is OK, it's the problem of the pit daddy

PS: I am a like in accordance with their own style to write code, whether it is the foreground or the background, as far as possible to do the code backup, when one day accidentally changed the code, then may not find the problem. When there is a problem in the day, can fall back to a point in the front of the code, then you can find some problems, like I encountered today's problem, nor no other solution. My solution is to fall back to the previous code, because I remember this piece is not a problem, all carefully check only to find that the header information changed

All I know about this tool now is Eclipse's show local history! This feature is backed up once every time it is saved and is very powerful and is stored on the local machine.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.