Skip to content

Instantly share code, notes, and snippets.

@Samjin
Last active July 5, 2016 06:34

Revisions

  1. Samjin renamed this gist Jul 5, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Samjin revised this gist Mar 24, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -21,4 +21,4 @@ $(window).scroll(throttle(function() {
    }, 250));


    http://ejohn.org/blog/learning-from-twitter/#postcomment
    https://github.com/shichuan/javascript-patterns/blob/master/jquery-patterns/window-scroll-event.html
  3. Samjin created this gist Mar 24, 2016.
    24 changes: 24 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    var throttle = (function () {
    return function (fn, delay) {
    delay || (delay = 100);
    var last = +new Date;
    return function () {
    var now = +new Date;
    if (now - last > delay) {
    fn.apply(this, arguments);
    last = now;
    }
    };
    };
    })();
    And then it can be used like this:

    var outerPane = $details.find(".details-pane-outer"),

    $(window).scroll(throttle(function() {
    // Check your page position and then
    // Load in more results
    }, 250));


    http://ejohn.org/blog/learning-from-twitter/#postcomment