0
所以,我有一个可以动画的对象(让我们称之为obj1)。其他对象可以在动画之前或之后动态创建,所以我希望它们的边距左边位置基于obj1的当前边距左边。jquery动画对象,然后创建其他对象基于新的margin-left
这是相关的代码片段。奇怪的是它与警报一起工作,但是如果我拿出警报,则余量将默认为最初在样式表中的内容。超时是为了确保新obj不会创建,直到前一个obj完成动画到新位置为止。
if(!rounds.match12) {
setTimeout(function() {
createMatchup(matchups[6].winner, matchups[7].winner, 12, false); //this creates a new matchup and appendsTo current container
var pos = $('#matchup5').css('margin-left');
alert(pos);
$('#matchup12').css('margin-left' , pos);
alert($('#matchup12').css('margin-left'));
$('#matchup12').css('margin-left' , '-=195');
alert($('#matchup12').css('margin-left'));
rounds.match12 = true;
},1500);
}
不幸的是,这对我不起作用。动画是一种可以应用于多种事情的自己的功能。新对象的创建不一定与动画相关。我真的只想让剩余的新对象边距基于剩下的其他对象。 – user1310774
@ user1310774你能用你的代码在jsfiddle.net上创建一个小提琴,因为这有助于我们提供答案。 – dSquared
我有点修复它我有css过渡包含元素,似乎然后与某些原因改变边际冲突。 – user1310774