According to this question, I need to chek if a property is not in an object:
So, we've some styling:
.foo {
top: 13px;
width: 37px;
}
...and an object like this one:
var keyframe = {
0: {
top: 0
},
1000: {
top: 100
},
2000: {
width: 100
}
};
now I need to iterate over all properties that are not in the next/previous frame-item, to populate the missing property with the css-values from an jQuery-object.
So that the final object looks like this:
var keyframe = {
0: {
top: 0,
width: '37px'
},
1000: {
top: 100,
width: '37px'
},
2000: {
top: 100,
width: 100
}
};
I've tried something like this:
http://fiddle.jshell.net/WdNge/
var $foo = $('.foo');
for (var key in keyframe) {
var obj = keyframe[key];
for(var ok in obj) {
if (!(ok in obj)) obj[ok] = $foo.css(ok);
}
}
But it seems that
if (!(ok in obj)) // is always `truthy`
however if I declare it directly
if (!('top' in obj)) // it works...
Any ideas?
Update
I even tried something like this, but no success:
http://fiddle.jshell.net/WdNge/1/
var $foo = $('.foo');
var keys = [];
for (var key in keyframe) {
var obj = keyframe[key];
var k = Object.keys(obj);
keys.push(k[0]);
for(var i = 0; i < keys.length; i++) {
var ok = keys[i];
if (!(ok in obj)) obj[ok] = $foo.css(ok);
}
}