|
New Core Effect: msg#00110lang.ruby.rails.spinoffs
Hey everyone, I've created a new "core" effect for use with a project I'm working on. Thought some people might find it useful. It takes a CSS parameter that has top, right, left, and bottom parameters and adjusts them as specified; useful making adjustments to page layouts (ie, hide one element and adjust another's margin to fill to void). I've not tested it a whole lot; it works with margins though (that's what I'm using it for). Stick it in with the core effects at the top of effects.js. Then add your usage function into effects.js...I've included a "right margin" adjustment here. Seems to work as far as I can tell; if you find any major issues, let me know. I'm using 1.5 RC 4, FYI. // call this function in your page Effect.ChangeRightMargin(elems[i], 210); // the secondary effect Effect.ChangeRightMargin = function(element, to) { element = $(element); new Effect.Adjust(element, 'margin', {toRight: to}); } // the core effect Effect.Adjust = Class.create(); Object.extend(Object.extend(Effect.Adjust.prototype, Effect.Base.prototype), { initialize: function(element, property) { this.element = $(element); this.property = property; var options = Object.extend({ toRight: null, toLeft: null, toTop: null, toBottom: null }, arguments[2] || {}); this.originalRight = parseFloat(Element.getStyle(this.element, property + '-right') || '0'); this.originalLeft = parseFloat(Element.getStyle(this.element, property + '-left') || '0'); this.originalTop = parseFloat(Element.getStyle(this.element, property + '-top') || '0'); this.originalBottom = parseFloat(Element.getStyle(this.element, property + '-bottom') || '0'); this.start(options); }, update: function(position) { rightd = (this.originalRight * (1-position)) + (this.options.toRight * position); leftd = (this.originalLeft * (1-position)) + (this.options.toLeft * position); topd = (this.originalTop * (1-position)) + (this.options.toTop * position); bottomd = (this.originalBottom * (1-position)) + (this.options.toBottom * position); this.makeAdjustment(rightd, leftd, topd, leftd); }, makeAdjustment: function(rightd, leftd, topd, bottomd) { if(this.options.toRight != null) { this.element.style[this.property + 'Right'] = rightd + "px"; } if(this.options.toLeft != null) { this.element.style[this.property+ 'Left'] = leftd + "px"; } if(this.options.toTop != null) { this.element.style[this.property + 'Top'] = topd + "px"; } if(this.options.toBottom != null) { this.element.style[this.property + 'Bottom'] = bottomd + "px"; } } }); -Jerod Venema |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | InPlaceEditor question: 00110, Brandon Dove |
|---|---|
| Next by Date: | Re: Looking to develop for scriptaculous: 00110, Jon Tirsen |
| Previous by Thread: | Re: Rails-spinoffs Digest, Vol 6, Issue 27i: 00110, Jonah Fox |
| Next by Thread: | Element.findElement - confusion: 00110, Marco M. Jaeger |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |