Skip to content

Commit eb42b2b

Browse files
Plugin rewritten so that unprefixed styles are added after ones that prefixed
Some browsers such as Opera 12.1 dropped prefixes support for animation styles so prefixed styles simply not working there. Also without regular unprefixed properties other browsers will finally end up using nonstandard prefixed property which is not good. So unprefixed version for all animation styles now added after prefixed ones.
1 parent 5414e72 commit eb42b2b

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

jquery.keyframes.js

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@
4343
return animationSupport;
4444
},
4545
generate: function(frameData) {
46-
var $elems, $frameStyle, css, frameName, property, key;
46+
var $elems, $frameStyle, css, frameName, property, key,
47+
prefix = $.keyframe.getVendorPrefix();
4748
frameName = frameData.name || "";
48-
css = "@" + $.keyframe.getVendorPrefix() + "keyframes " + frameName + " {";
49+
css = "@" + prefix + "keyframes " + frameName + " {";
4950

5051
for (key in frameData) {
5152
if (key !== "name") {
@@ -61,13 +62,16 @@
6162

6263
css = PrefixFree.prefixCSS(css + "}");
6364

65+
css += css.replace($.keyframe.getVendorPrefix(), '');
66+
6467
$frameStyle = $("style#" + frameData.name);
6568

6669
if ($frameStyle.length > 0) {
6770
$frameStyle.html(css);
6871

6972
$elems = $("*").filter(function() {
70-
this.style["" + ($.keyframe.getVendorPrefix().slice(1, -1)) + "AnimationName"] === frameName;
73+
return this.style["" + (prefix.slice(1, -1)) + "AnimationName"] === frameName ||
74+
this.style["AnimationName"] === frameName;
7175
});
7276

7377
$elems.each(function() {
@@ -101,19 +105,31 @@
101105
playStateRunning = "running";
102106

103107
$.fn.resetKeyframe = function(callback) {
104-
var $el = $(this).css(vendorPrefix + animationPlayState, playStateRunning).css(vendorPrefix + "animation", "none");
108+
var $el = $(this),
109+
css = {};
110+
111+
css[animationPlayState] = css[vendorPrefix + animationPlayState] = playStateRunning;
112+
css["animation"] = css[vendorPrefix + "animation"] = "none";
113+
114+
$el.css(css);
105115

106116
if (callback) {
107117
setTimeout(callback, 1);
108118
}
109119
};
110120

111121
$.fn.pauseKeyframe = function() {
112-
var $el = $(this).css(vendorPrefix + animationPlayState, "paused");
122+
var $el= $(this),
123+
css = {};
124+
css[animationPlayState] = css[vendorPrefix + animationPlayState] = "paused";
125+
$el.css(css);
113126
};
114127

115128
$.fn.resumeKeyframe = function() {
116-
return $(this).css(vendorPrefix + animationPlayState, playStateRunning);
129+
var $el= $(this),
130+
css = {};
131+
css[animationPlayState] = css[vendorPrefix + animationPlayState] = playStateRunning;
132+
return $el.css(css);
117133
};
118134

119135
$.fn.playKeyframe = function(frameOptions, callback) {
@@ -148,7 +164,7 @@
148164
repeat = frameOptions.repeat;
149165
animationcss = "" + frameOptions.name + " " + duration + "ms " + frameOptions.timingFunction + " " + delay + "ms " + repeat + " " + frameOptions.direction + " " + frameOptions.fillMode;
150166
callback = frameOptions.complete;
151-
animationkey = vendorPrefix + "animation";
167+
animationkey = "animation";
152168
pfx = ["webkit", "moz", "MS", "o", ""];
153169

154170
var _prefixEvent = function(element, type, callback) {
@@ -167,7 +183,13 @@
167183
};
168184

169185
this.each(function() {
170-
var $el = $(this).addClass("boostKeyframe").css(vendorPrefix + animationPlayState, playStateRunning).css(animationkey, animationcss).data("keyframeOptions", frameOptions);
186+
var $el = $(this).addClass("boostKeyframe").data("keyframeOptions", frameOptions),
187+
css = {};
188+
189+
css[animationPlayState] = css[vendorPrefix + animationPlayState] = playStateRunning;
190+
css[animationkey] = css[vendorPrefix + animationkey] = animationcss;
191+
192+
$el.css(css);
171193
if (callback) {
172194
_prefixEvent($el, 'AnimationIteration', callback);
173195
_prefixEvent($el, 'AnimationEnd', callback);
@@ -180,4 +202,4 @@
180202
id: "boost-keyframe"
181203
}).append(" .boostKeyframe{" + vendorPrefix + "transform:scale3d(1,1,1);}");
182204

183-
}).call(this);
205+
}).call(this);

0 commit comments

Comments
 (0)