最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Detect if user browser-height >= page body-height - Stack Overflow

programmeradmin1浏览0评论

I am running in a bit of a problem here trying to figure out this one. I already coded a jquery function that detects when the user hits the bottom of the page and trigger an function. Now, while this works alright for the most mon screen-sizes, it will not work when the user has a screen so big that sees the entire page at once, rendering the previous function useless.

What I am trying to achive is the fallback for those cases, how can I tell if the user has such a screensize that will trigger the function and leave the rest to the other?

Better explained: How to detect if the user browser-height is equal or greater than the page body height?

Sorry if this looks a bit confusing.

PS: The following code is the one I am using when the browser-height is smaller than the page body-height.

    if ($('body').height() <= ($(window).height() + $(window).scrollTop())) {
        //run function here when the browser-height is smaller than
        //the page's height and it has reached the bottom
    }

I am running in a bit of a problem here trying to figure out this one. I already coded a jquery function that detects when the user hits the bottom of the page and trigger an function. Now, while this works alright for the most mon screen-sizes, it will not work when the user has a screen so big that sees the entire page at once, rendering the previous function useless.

What I am trying to achive is the fallback for those cases, how can I tell if the user has such a screensize that will trigger the function and leave the rest to the other?

Better explained: How to detect if the user browser-height is equal or greater than the page body height?

Sorry if this looks a bit confusing.

PS: The following code is the one I am using when the browser-height is smaller than the page body-height.

    if ($('body').height() <= ($(window).height() + $(window).scrollTop())) {
        //run function here when the browser-height is smaller than
        //the page's height and it has reached the bottom
    }
Share Improve this question edited Apr 12, 2012 at 19:49 Shadow asked Apr 12, 2012 at 19:42 ShadowShadow 4,7926 gold badges59 silver badges79 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7
    if ($(document).height() <= $(window).height() ) { }

$(document).height(); // returns height of HTML document

Use document height instead.

if ($(document).height() <= $(window).height())
{..}
发布评论

评论列表(0)

  1. 暂无评论