Jump to content
Search Community

martinambrus

Members
  • Posts

    8
  • Joined

  • Last visited

Community Answers

  1. martinambrus's post in Window Auto-Scroll for Draggable? was marked as the answer   
    I've actually found a nice jQuery plugin that enables auto-scroll for droppables: https://groups.google.com/forum/#!searchin/threedubmedia/autoscroll/threedubmedia/Ffues0BsuN8/s9syU7PGgUUJ
     
    I believe the code from it can be extracted and updated for use outside of jQuery as well, so I will post it here for reference (in case the link stops working):
     
    jQuery.fn.autoScroll = function( arg, opts ){          opts = opts || {};          // the main element          var elem = this[0],          // the coordinates to calculate          XX = arg.pageX || arg.left || arg[0] || 0,          YY = arg.pageY || arg.top || arg[1] || 0,          // the optional options...          buffer = opts.buffer || 100, // pixels from edge          dist = opts.distance || 20, // pixels to scroll per call          // page/document scrolling...          page = !elem.ownerDocument || jQuery.nodeName(elem,'html'),          // the element to utilize          $elem = page ? jQuery( window ) : this.eq(0),          // the parameters to modify...          top = $elem.scrollTop(), left = $elem.scrollLeft(),          // attributes to calculate position          offset = page ? { top:0, left:0 } : $elem.offset(),          // calculate buffer zones          south = YY - offset.top - ( page ? top : 0 ),          north = $elem.height() + offset.top - YY - ( page ? top : 0 ),          east = XX - offset.left - ( page ? left : 0 ),          west = $elem.width() + offset.left - XX - ( page ? left : 0 ),          // calculate the distance to move...          vert = south < buffer ? -dist : north < buffer ? dist : 0,          hori = east < buffer ? -dist : west < buffer ? dist : 0;          // set the vertical scroll          if ( vert != 0 ) $elem.scrollTop( top + vert );          // set the horizontal scroll          if ( hori != 0 ) $elem.scrollLeft( left + hori );          // preserve jquery chain...          return this;  }; $( window ).autoScroll( event );  Thanks for the pointer though, Jack
×
×
  • Create New...