2

Ho can I transform my following lazy loading with more button to lazy loading with on scroll loading?

function openFromButton(lastLoadedIndex) {
    lastLoadedIndex = (typeof(lastLoadedIndex)=='undefined') ? '' : lastLoadedIndex;
    jQuery.get('liste.asp?from_item='+ lastLoadedIndex +'&param='+(new Date()).getTime(), function(data) { 
//alert(data);
        jQuery("#liste_body").append(data);
    });

This what I've have done so far, it works fine, but the problem is it loads when I scroll vertically or horizontally. How can I just make it work on vertical scroll ?

function addEvent( obj, type, fn ) {
    if ( obj.attachEvent ) {
        obj['e'+type+fn] = fn;
        obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
        obj.attachEvent( 'on'+type, obj[type+fn] );
    } else
        obj.addEventListener( type, fn, false );
    }
    addEvent(window, 'scroll', function(event) {
    openFromButton();
});
Jeff
  • 13,943
  • 11
  • 55
  • 103
N.G
  • 134
  • 1
  • 9
  • No need for the [tag:asp-classic] tag; you may get more results with the [tag:javascript] tag... – Paul Sep 12 '14 at 14:18
  • You'll have to trigger your loading action on a scroll-related event instead of a button click. For inspiration, see http://stackoverflow.com/questions/21561480/trigger-event-when-user-scroll-to-specific-element-with-jquery – Palpatim Sep 12 '14 at 14:33
  • Just add a scroll listener and call that function when you're X pixels from the bottom. – Shomz Sep 12 '14 at 14:33
  • N.G. If you can't take the time to spell words correctly and present your post in a legible format, why should other people take the time to read it and help you out? – Jeff Sep 12 '14 at 15:21
  • 1
    @Jeff I edited my post when I realized my typing mistakes; you 've probably jumped on making a comment before refreshing and making sure if I have corrected my mistakes or not – N.G Sep 12 '14 at 15:24
  • @N.G Glad to see that you editted it! – Jeff Sep 12 '14 at 16:57
  • 1
    @Jeff: PS - you spelled `edited` incorrectly! ;o) – Paul Sep 15 '14 at 11:04

1 Answers1

2

This is the solution that worked for me, tested on chrome, firefox and IE

   var lastScrollTop = 0;
  $(window).scroll(function(event){
      var st = $(this).scrollTop();
          if (st > lastScrollTop){
            Load()
          } else {
                  }
     lastScrollTop = st;
    });

EDIT : Note that $(this).scrollTop(); doesn't work on IE 8, to make it work , I replaced it by document.body.scrollTop

N.G
  • 134
  • 1
  • 9