2

我在页面上有想要动画查看的元素,但是在它们动画之后,我想将它们的进一步动画推迟到 CSS(通过更改类)......我发现 Velocity 留下了我所有的动画标记中的属性style=并使 CSS 过渡变得不可能。

我在下面有一个解决方案,但是在complete上重置 CSS 似乎有问题,我想知道是否有更好的方法来做到这一点?

// first use CSS to hide the element and squish it
$el.css({ 
    width: 0, 
    left: "-10px", 
    opacity: 0,
    marginRight: 0,
    transition: "none"
})

// now animate the width and margin (do this first
// so there's a little gap between existing elements
// before we fade in new element.
.velocity({ 
    width: width,
    marginRight: margin
}, {
    queue: false,
    duration: 230
})

// then fade and move in the new element,
// but this is the iffy bit when it completes
// I have to unset all the styles I've animated?
.velocity({ 
    left: 0, 
    opacity: 1 
}, {
    queue: false,
    duration: 100,
    delay: 130,
    complete: function(els) {

        $(els).css({
            width: "",
            left: "",
            opacity: "",
            marginRight: "",
            transition: ""
         });             
    }
});
4

1 回答 1

6

通常,您希望动画引擎内联样式;否则最终值将弹出,因为它们在删除时被样式表覆盖。

您也可以$(els).attr("style", "");清除所有样式。

于 2014-10-02T18:33:47.613 回答