MCPcopy Create free account
hub / github.com/codrops/RainEffect / _cssDif

Function _cssDif

demo/js/index.js:6646–6666  ·  view source on GitHub ↗
(t, s1, s2, vars, forceLookup)

Source from the content-addressed store, hash-verified

6644
6645 // @private analyzes two style objects (as returned by _getAllStyles()) and only looks for differences between them that contain tweenable values (like a number or color). It returns an object with a "difs" property which refers to an object containing only those isolated properties and values for tweening, and a "firstMPT" property which refers to the first MiniPropTween instance in a linked list that recorded all the starting values of the different properties so that we can revert to them at the end or beginning of the tween - we don't want the cascading to get messed up. The forceLookup parameter is an optional generic object with properties that should be forced into the results - this is necessary for className tweens that are overwriting others because imagine a scenario where a rollover/rollout adds/removes a class and the user swipes the mouse over the target SUPER fast, thus nothing actually changed yet and the subsequent comparison of the properties would indicate they match (especially when px rounding is taken into consideration), thus no tweening is necessary even though it SHOULD tween and remove those properties after the tween (otherwise the inline styles will contaminate things). See the className SpecialProp code for details.
6646 _cssDif = function(t, s1, s2, vars, forceLookup) {
6647 var difs = {},
6648 style = t.style,
6649 val, p, mpt;
6650 for (p in s2) {
6651 if (p !== "cssText") if (p !== "length") if (isNaN(p)) if (s1[p] !== (val = s2[p]) || (forceLookup && forceLookup[p])) if (p.indexOf("Origin") === -1) if (typeof(val) === "number" || typeof(val) === "string") {
6652 difs[p] = (val === "auto" && (p === "left" || p === "top")) ? _calculateOffset(t, p) : ((val === "" || val === "auto" || val === "none") && typeof(s1[p]) === "string" && s1[p].replace(_NaNExp, "") !== "") ? 0 : val; //if the ending value is defaulting ("" or "auto"), we check the starting value and if it can be parsed into a number (a string which could have a suffix too, like 700px), then we swap in 0 for "" or "auto" so that things actually tween.
6653 if (style[p] !== undefined) { //for className tweens, we must remember which properties already existed inline - the ones that didn't should be removed when the tween isn't in progress because they were only introduced to facilitate the transition between classes.
6654 mpt = new MiniPropTween(style, p, style[p], mpt);
6655 }
6656 }
6657 }
6658 if (vars) {
6659 for (p in vars) { //copy properties (except className)
6660 if (p !== "className") {
6661 difs[p] = vars[p];
6662 }
6663 }
6664 }
6665 return {difs:difs, firstMPT:mpt};
6666 },
6667 _dimensions = {width:["Left","Right"], height:["Top","Bottom"]},
6668 _margins = ["marginLeft","marginRight","marginTop","marginBottom"],
6669

Callers 1

index.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected