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();
});
7
  • No need for the asp-classic tag; you may get more results with the javascript tag... Commented Sep 12, 2014 at 14:18
  • You'll have to trigger your loading action on a scroll-related event instead of a button click. For inspiration, see stackoverflow.com/questions/21561480/… Commented Sep 12, 2014 at 14:33
  • Just add a scroll listener and call that function when you're X pixels from the bottom. Commented Sep 12, 2014 at 14:33
  • 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 Commented Sep 12, 2014 at 15:24
  • 1
    @Jeff: PS - you spelled edited incorrectly! ;o) Commented Sep 15, 2014 at 11:04

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.