swap.js 555 B

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