Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Effect.ScaleAndMove = Class.create(Effect.Base, {
- initialize: function(element, percentX, percentY) {
- this.element = $(element);
- if(!this.element) throw(Effect._elementDoesNotExistError);
- var options = Object.extend({
- scaleX: true,
- scaleY: true,
- moveX: true,
- moveY: true,
- scaleMode: 'box', // 'box' or 'contents' or { } with provided values
- scaleFromX: 100.0,
- scaleToX: percentX,
- scaleFromY: 100.0,
- scaleToY: percentY,
- moveToX: null,
- moveToY: null
- }, arguments[3] || { });
- this.start(options);
- },
- setup: function() {
- this.restoreAfterFinish = this.options.restoreAfterFinish || false;
- this.elementPositioning = this.element.getStyle('position');
- this.originalStyle = { };
- ['top','left','width','height'].each(function(k) {
- this.originalStyle[k] = this.element.style[k];
- }.bind(this));
- this.originalTop = this.element.offsetTop;
- this.originalLeft = this.element.offsetLeft;
- this.scaleFactorX = (this.options.scaleToX - this.options.scaleFromX) / 100;
- this.scaleFactorY = (this.options.scaleToY - this.options.scaleFromY) / 100;
- this.moveFactorX = this.options.moveToX - this.originalLeft;
- this.moveFactorY = this.options.moveToY - this.originalTop;
- this.dims = null;
- if(this.options.scaleMode=='box') {
- this.dims = [this.element.offsetHeight, this.element.offsetWidth];
- } else if(/^content/.test(this.options.scaleMode)) {
- this.dims = [this.element.scrollHeight, this.element.scrollWidth];
- } else {
- this.dims = [this.options.scaleMode.originalHeight, this.options.scaleMode.originalWidth];
- }
- },
- update: function(position) {
- var currentScaleX = (this.options.scaleFromX / 100.0) + (this.scaleFactorX * position);
- var currentScaleY = (this.options.scaleFromY / 100.0) + (this.scaleFactorY * position);
- var currentMoveX = this.moveFactorX * position;
- var currentMoveY = this.moveFactorY * position;
- this.setDimensionsAndPosition(
- this.dims[0] * currentScaleY,
- this.dims[1] * currentScaleX,
- this.originalTop + currentMoveY,
- this.originalLeft + currentMoveX
- );
- },
- finish: function(position) {
- if(this.restoreAfterFinish) this.element.setStyle(this.originalStyle);
- },
- setDimensionsAndPosition: function(height, width, top, left) {
- var d = { };
- if(this.options.scaleX) d.width = width.round() + 'px';
- if(this.options.scaleY) d.height = height.round() + 'px';
- if(this.options.moveX) d.left = left.round() + 'px';
- if(this.options.moveY) d.top = top.round() + 'px';
- this.element.setStyle(d);
- }
- });
Add Comment
Please, Sign In to add comment