Guest User

Untitled

a guest
Jun 24th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1.  
  2.  
  3. addClass: function(classNames, speed, easing, callback) {
  4. return speed ? $.effects.animateClass.apply(this, [{ add: classNames },speed,easing,callback]) : this._addClass(classNames);
  5. },
  6. removeClass: function(classNames,speed,easing,callback) {
  7. return speed ? $.effects.animateClass.apply(this, [{ remove: classNames },speed,easing,callback]) : this._removeClass(classNames);
  8. },
  9. toggleClass: function(classNames,speed,easing,callback) {
  10. return ( (typeof speed !== "boolean") && speed ) ? $.effects.animateClass.apply(this, [{ toggle: classNames },speed,easing,callback]) : this._toggleClass(classNames, speed);
  11. },
  12. morph: function(remove,add,speed,easing,callback) {
  13. return $.effects.animateClass.apply(this, [{ add: add, remove: remove },speed,easing,callback]);
  14. },
  15. switchClass: function() {
  16. return this.morph.apply(this, arguments);
  17. },
  18.  
  19.  
  20. // .... and animateClass...
  21.  
  22.  
  23. //Base function to animate from one class to another in a seamless transition
  24. animateClass: function(value, duration, easing, callback) {
  25.  
  26. var cb = (typeof easing == "function" ? easing : (callback ? callback : null));
  27. var ea = (typeof easing == "string" ? easing : null);
  28.  
  29. return this.each(function() {
  30.  
  31. var offset = {}; var that = $(this); var oldStyleAttr = that.attr("style") || '';
  32. if(typeof oldStyleAttr == 'object') oldStyleAttr = oldStyleAttr["cssText"]; /* Stupidly in IE, style is a object.. */
  33. if(value.toggle) { that.hasClass(value.toggle) ? value.remove = value.toggle : value.add = value.toggle; }
  34.  
  35. //Let's get a style offset
  36. var oldStyle = $.extend({}, (document.defaultView ? document.defaultView.getComputedStyle(this,null) : this.currentStyle));
  37. if(value.add) that.addClass(value.add); if(value.remove) that.removeClass(value.remove);
  38. var newStyle = $.extend({}, (document.defaultView ? document.defaultView.getComputedStyle(this,null) : this.currentStyle));
  39. if(value.add) that.removeClass(value.add); if(value.remove) that.addClass(value.remove);
  40.  
  41. // The main function to form the object for animation
  42. for(var n in newStyle) {
  43. if( typeof newStyle[n] != "function" && newStyle[n] /* No functions and null properties */
  44. && n.indexOf("Moz") == -1 && n.indexOf("length") == -1 /* No mozilla spezific render properties. */
  45. && newStyle[n] != oldStyle[n] /* Only values that have changed are used for the animation */
  46. && (n.match(/color/i) || (!n.match(/color/i) && !isNaN(parseInt(newStyle[n],10)))) /* Only things that can be parsed to integers or colors */
  47. && (oldStyle.position != "static" || (oldStyle.position == "static" && !n.match(/left|top|bottom|right/))) /* No need for positions when dealing with static positions */
  48. ) offset[n] = newStyle[n];
  49. }
  50.  
  51. that.animate(offset, duration, ea, function() { // Animate the newly constructed offset object
  52. // Change style attribute back to original. For stupid IE, we need to clear the damn object.
  53. if(typeof $(this).attr("style") == 'object') { $(this).attr("style")["cssText"] = ""; $(this).attr("style")["cssText"] = oldStyleAttr; } else $(this).attr("style", oldStyleAttr);
  54. if(value.add) $(this).addClass(value.add); if(value.remove) $(this).removeClass(value.remove);
  55. if(cb) cb.apply(this, arguments);
  56. });
  57.  
  58. });
  59. }
Add Comment
Please, Sign In to add comment