Thursday, October 13, 2011

Facebook detect movement before loading new feeds

If you are eagle-eyed enough, you would have noticed that facebook actually doesn't poll unnecessarily from the server. Somehow it knows that you are away for sometime and when you are active and start to move your mouse, newer feeds starts loading.


<script type="text/javascript">
  document.onmousemove = (function() {
    var onmousestop = function() {
      $('h1').css("color", "white");
    }, thread;
    return function() {
      $('h1').css("color", "red") clearTimeout(thread);
      thread = setTimeout(onmousestop, 200);
    };
  })();


Read more on this: Closures
I've embedded this scrip into the blog -> Blue H1, so don't panic if you see the h1 starts turning blue :)