scroll.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. define("dojox/fx/scroll", ["dojo/_base/kernel","dojo/_base/lang", "dojo/_base/fx", "dojox/fx/_base","dojox/fx/_core","dojo/dom-geometry","dojo/_base/sniff"],
  2. function (kernel, lang, baseFx, fxExt, Line, domGeom, has){
  3. kernel.experimental("dojox.fx.scroll");
  4. var fx = lang.getObject("dojox.fx",true);
  5. fxExt.smoothScroll = function(/* Object */args){
  6. // summary: Returns an animation that will smooth-scroll to a node
  7. // description: This implementation support either horizontal or vertical scroll, as well as
  8. // both. In addition, element in iframe can be scrolled to correctly.
  9. // offset: {x: int, y: int} this will be added to the target position
  10. // duration: Duration of the animation in milliseconds.
  11. // win: a node or window object to scroll
  12. if(!args.target){ args.target = domGeom.position(args.node); }
  13. var isWindow = lang[(has("ie") ? "isObject" : "isFunction")](args["win"].scrollTo),
  14. delta = { x: args.target.x, y: args.target.y }
  15. ;
  16. if(!isWindow){
  17. var winPos = domGeom.position(args.win);
  18. delta.x -= winPos.x;
  19. delta.y -= winPos.y;
  20. }
  21. var _anim = (isWindow) ?
  22. (function(val){
  23. args.win.scrollTo(val[0],val[1]);
  24. }) :
  25. (function(val){
  26. args.win.scrollLeft = val[0];
  27. args.win.scrollTop = val[1];
  28. });
  29. var anim = new baseFx.Animation(lang.mixin({
  30. beforeBegin: function(){
  31. if(this.curve){ delete this.curve; }
  32. var current = isWindow ? dojo._docScroll() : {x: args.win.scrollLeft, y: args.win.scrollTop};
  33. anim.curve = new Line([current.x,current.y],[current.x + delta.x, current.y + delta.y]);
  34. },
  35. onAnimate: _anim
  36. },args));
  37. return anim; // dojo.Animation
  38. };
  39. fx.smoothScroll = fxExt.smoothScroll;
  40. return fxExt.smoothScroll;
  41. });