Guest User

Untitled

a guest
May 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. Effect.ScaleAndMove = Class.create(Effect.Base, {
  2. initialize: function(element, percentX, percentY) {
  3. this.element = $(element);
  4. if(!this.element) throw(Effect._elementDoesNotExistError);
  5. var options = Object.extend({
  6. scaleX: true,
  7. scaleY: true,
  8. moveX: true,
  9. moveY: true,
  10. scaleMode: 'box', // 'box' or 'contents' or { } with provided values
  11. scaleFromX: 100.0,
  12. scaleToX: percentX,
  13. scaleFromY: 100.0,
  14. scaleToY: percentY,
  15. moveToX: null,
  16. moveToY: null
  17. }, arguments[3] || { });
  18. this.start(options);
  19. },
  20. setup: function() {
  21. this.restoreAfterFinish = this.options.restoreAfterFinish || false;
  22. this.elementPositioning = this.element.getStyle('position');
  23.  
  24. this.originalStyle = { };
  25. ['top','left','width','height'].each(function(k) {
  26. this.originalStyle[k] = this.element.style[k];
  27. }.bind(this));
  28.  
  29. this.originalTop = this.element.offsetTop;
  30. this.originalLeft = this.element.offsetLeft;
  31.  
  32. this.scaleFactorX = (this.options.scaleToX - this.options.scaleFromX) / 100;
  33. this.scaleFactorY = (this.options.scaleToY - this.options.scaleFromY) / 100;
  34.  
  35. this.moveFactorX = this.options.moveToX - this.originalLeft;
  36. this.moveFactorY = this.options.moveToY - this.originalTop;
  37.  
  38. this.dims = null;
  39. if(this.options.scaleMode=='box') {
  40. this.dims = [this.element.offsetHeight, this.element.offsetWidth];
  41. } else if(/^content/.test(this.options.scaleMode)) {
  42. this.dims = [this.element.scrollHeight, this.element.scrollWidth];
  43. } else {
  44. this.dims = [this.options.scaleMode.originalHeight, this.options.scaleMode.originalWidth];
  45. }
  46. },
  47. update: function(position) {
  48. var currentScaleX = (this.options.scaleFromX / 100.0) + (this.scaleFactorX * position);
  49. var currentScaleY = (this.options.scaleFromY / 100.0) + (this.scaleFactorY * position);
  50.  
  51. var currentMoveX = this.moveFactorX * position;
  52. var currentMoveY = this.moveFactorY * position;
  53.  
  54. this.setDimensionsAndPosition(
  55. this.dims[0] * currentScaleY,
  56. this.dims[1] * currentScaleX,
  57. this.originalTop + currentMoveY,
  58. this.originalLeft + currentMoveX
  59. );
  60. },
  61. finish: function(position) {
  62. if(this.restoreAfterFinish) this.element.setStyle(this.originalStyle);
  63. },
  64. setDimensionsAndPosition: function(height, width, top, left) {
  65. var d = { };
  66. if(this.options.scaleX) d.width = width.round() + 'px';
  67. if(this.options.scaleY) d.height = height.round() + 'px';
  68. if(this.options.moveX) d.left = left.round() + 'px';
  69. if(this.options.moveY) d.top = top.round() + 'px';
  70. this.element.setStyle(d);
  71. }
  72. });
Add Comment
Please, Sign In to add comment