$ (window). Height () document altitude problem

Source: Internet
Author: User
Tags window xmlns

Encountered a problem such as:

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

First, describe the function of the problem:

A way to find the web when you do a scroll bar drop load

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

When we show the scroll bar, we can create events by pulling the scroll bar down so that we can add the contents of the page that we need to load in the event, and many websites do this to save the pressure on the picture server.

But doing it today is found to run normally on IE, running on Google and Firefox is not normal. Because of the use of IE testing, so, do not know where the change will lead to this error, error occurs as follows

The normal situation is

When the scroll bar hits the bottom, it triggers the event, so I can load what I need because $ (document). ScrollTop () >=$ (document). Height ()-$ (window). Height () means When the scroll bar height is greater than the height of the window-the height of the document, the event is triggered, and all the effects shown above are seen!

However, the following error occurred:

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

These two values are printed later: this $ (document) is found. Height () and $ (window). Height () The two values in Google and Firefox are the same value, in IE is different, that is, no matter how the scroll bar, This judgment condition is always set up, so there is nothing on IE, other browsers appear incorrect.

Solution:

If you've changed the same thing 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 into

Finally, the problem is solved.

That is, $ (window). The value of height () is normal, it's a question of pit dad.

PS: I am a like to write the code according to their own style, whether it is the foreground or backstage, as far as possible to do the code backup, when the day has no intention to change the code, then may not find the problem. When there is a problem, the code that can fall back to a point in time, you can look up some problems, like the problem I'm having today, and there's no other way around. My solution is to fall back to the previous code, because I remember the previous piece is no problem, all carefully checked only to find that the change of the head information

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.