bhalash

Example recursive function

Jun 3rd, 2014
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function wrap(obj) {
  2.     // Wraps the container if it scrolls off the screen entirely.
  3.     var x = $(obj).offset().left;
  4.     var y = $(obj).offset().top;
  5.     var h = $(obj).height();
  6.     var w = $(obj).width();
  7.  
  8.     if (y + h < 0) {
  9.         $(obj).css('top', $(window).height() + 'px');
  10.     } else if (w + x < 0) {
  11.         $(obj).css('left', $(window).width() + 'px');
  12.     } else if (x > $(window).width()) {
  13.         $(obj).css('left', 0 - w + 'px');
  14.     } else if (y > $(window).height()) {
  15.         $(obj).css('top', 0 - h + 'px');
  16.     }
  17. }
  18.  
  19. function left(amount, obj) {
  20.     // Move element left.
  21.     $(obj).children().each(function() {
  22.         if ($(this).children().length > 0) {
  23.             left(amount, jQuery(this));
  24.         } else {
  25.             $(this).css('left', parseInt($(this).css('left')) - amount + 'px');
  26.             wrap(this);
  27.         }
  28.     });
  29. }
Advertisement
Add Comment
Please, Sign In to add comment