1 /** 2 * @fileOverview special patch for anim backgroundPosition 3 * @author yiminghe@gmail.com 4 */ 5 KISSY.add("anim/backgroundPosition", function (S, DOM, Anim, Fx) { 6 7 function numeric(bp) { 8 bp = bp.replace(/left|top/g, '0px') 9 .replace(/right|bottom/g, '100%') 10 .replace(/([0-9\.]+)(\s|\)|$)/g, "$1px$2"); 11 var res = bp.match(/(-?[0-9\.]+)(px|%|em|pt)\s(-?[0-9\.]+)(px|%|em|pt)/); 12 return [parseFloat(res[1]), res[2], parseFloat(res[3]), res[4]]; 13 } 14 15 function BackgroundPositionFx() { 16 BackgroundPositionFx.superclass.constructor.apply(this, arguments); 17 } 18 19 S.extend(BackgroundPositionFx, Fx, { 20 21 load:function () { 22 var self = this, fromUnit; 23 BackgroundPositionFx.superclass.load.apply(self, arguments); 24 fromUnit = self.unit = ["px", "px"]; 25 if (self.from) { 26 var from = numeric(self.from); 27 self.from = [from[0], from[2]]; 28 fromUnit = [from[1], from[3]]; 29 } else { 30 self.from = [0, 0]; 31 } 32 if (self.to) { 33 var to = numeric(self.to); 34 self.to = [to[0], to[2]]; 35 self.unit = [to[1], to[3]]; 36 } else { 37 self.to = [0, 0]; 38 } 39 if (fromUnit) { 40 if (fromUnit[0] !== self.unit[0] || fromUnit[1] !== self.unit[1]) { 41 S.log("BackgroundPosition x y unit is not same :", "warn"); 42 S.log(fromUnit, "warn"); 43 S.log(self.unit, "warn"); 44 } 45 } 46 }, 47 48 interpolate:function (from, to, pos) { 49 var unit = this.unit, interpolate = BackgroundPositionFx.superclass.interpolate; 50 return interpolate(from[0], to[0], pos) + unit[0] + " " + 51 interpolate(from[1], to[1], pos) + unit[1]; 52 }, 53 54 cur:function () { 55 return DOM.css(this.anim.elem, "backgroundPosition"); 56 }, 57 58 update:function () { 59 var self = this, 60 prop = self.prop, 61 elem = self.anim.elem, 62 from = self.from, 63 to = self.to, 64 val = self.interpolate(from, to, self.pos); 65 DOM.css(elem, prop, val); 66 } 67 68 }); 69 70 Fx.Factories["backgroundPosition"] = BackgroundPositionFx; 71 72 return BackgroundPositionFx; 73 74 }, { 75 requires:["dom", "./base", "./fx"] 76 });