1

There is nothing called scrollBottom() in jQuery, so I can't do $(window).scrollBottom()==0

Hope the question is clear from the title itself. Any help would be greatly appreciated. I'm mostly interested in IE7+, FF3.5+ (Chrome etc are bonus!)

Thanks!

Ajinkya
  • 22,324
  • 33
  • 110
  • 161
ragebiswas
  • 3,818
  • 9
  • 38
  • 39
  • Read this link http://ettoz.wordpress.com/2009/04/16/jquery-fixed-bar/ – Mohan Ram Dec 20 '10 at 11:48
  • It wont solve your problem but helps to your problem – Mohan Ram Dec 20 '10 at 11:49
  • How does this solve my problem? Do you mean adding a fixed bar to the bottom... or something? – ragebiswas Dec 20 '10 at 12:49
  • 1
    That plugin does not work in all IEs yet. But the idea is nice. You can check this in this fiddle http://jsfiddle.net/sandeepan_nits/X7bDC/11/ If you can find some other stable plugin which can put such a div at the bottom of the window, hovering over that div becomes equivalent to reaching the bottom. Good luck! – Sandeepan Nath Dec 20 '10 at 16:23
  • looks like stoefln solution applies this idea. do let us know what works better – Sandeepan Nath Dec 24 '10 at 10:40

3 Answers3

2

you could use this function to check whether an element is visible (e.g. a element at the bottom of the page):

function isScrolledIntoView(elem)
{
    var docViewTop = $(window).scrollTop();
    var docViewBottom = docViewTop + $(window).height();

    var elemTop = $(elem).offset().top;
    var elemBottom = elemTop + $(elem).height();

    return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom));
}

I implemented an endless scrolling effect (like in facebook) with it.

you can check each time, the user is scrolling the window:

function checkAndLoad(){
    if(isScrolledIntoView($('#footer'))){
        triggerSomething(); // 
    }
}
$(document).ready(function(){
    checkAndLoad();
    $(window).scroll(function(){
        checkAndLoad();
    });
});
stoefln
  • 14,498
  • 18
  • 79
  • 138
  • Stoefln, I basically just want to see if I'm near the bottom of the page. My question is exactly the same as http://stackoverflow.com/questions/3057892/checking-is-near-at-the-bottom-of-the-page - except that the solution given doesn't work in IE8 for me. – ragebiswas Dec 20 '10 at 10:23
2

<ironic>Use javascript.</ironic>

Browser support for this is a mixed bag. Non-IE you can use window.pageYOffset, with IE you have to use either document.body.scrollTop or document.documentElement.scrollTop depending on the browser version and compatability mode.

You may have to do some varying levels of mathematical manipualtion to the results - I don't have access to multiple browsers to test at work (I know) and I can't recall the detail of how these work offhand.

annakata
  • 74,572
  • 17
  • 113
  • 180
2

Check if this works

http://jsfiddle.net/sandeepan_nits/3Ys35/2/

I compared the e.pageY and $(document).height() but the fiddle example does not work accurately for all browsers and there is an offset problem. If I set an offset of 1 it works fine in ff.

If nothing else works perfect you may set different offsets based on browsers (IEs will need separate and others separate probably) or else replace the equal condition ( if(e.pageY == ($(document).height() - offset)) ) with a range check ( if((e.pageY < ($(document).height() + upperLimit)) && (e.pageY > ($(document).height() + lowerLimit))) ) if that is ok as per your requirement.

Sandeepan Nath
  • 9,966
  • 17
  • 86
  • 144
  • Thanks Sandeepan, but is this working in IE8 for you? I mean the "reached bottom" never appears. Unfortunately I need exact pixels from the bottom. – ragebiswas Dec 20 '10 at 10:38
  • 1
    @Raj - check http://jsfiddle.net/sandeepan_nits/3Ys35/7/ offset=16 works with IE 6 for me. I guess this is the closest you can reach with this method. Once you are sure with the needed offsets, you browser detection, or better jquery's feature detection to put the conditions. – Sandeepan Nath Dec 20 '10 at 10:50
  • Thanks, but I don't think various offsets with various browsers is a clean solution :( – ragebiswas Dec 20 '10 at 12:50