swap.js 520 B

1234567891011121314151617181920212223242526
  1. define( function() {
  2. "use strict";
  3. // A method for quickly swapping in/out CSS properties to get correct calculations.
  4. return function( elem, options, callback, args ) {
  5. var ret, name,
  6. old = {};
  7. // Remember the old values, and insert the new ones
  8. for ( name in options ) {
  9. old[ name ] = elem.style[ name ];
  10. elem.style[ name ] = options[ name ];
  11. }
  12. ret = callback.apply( elem, args || [] );
  13. // Revert the old values
  14. for ( name in options ) {
  15. elem.style[ name ] = old[ name ];
  16. }
  17. return ret;
  18. };
  19. } );