Velocity.js在动画后清除默认值

sim*_*.me 2 javascript css jquery animation velocity.js

我在页面上有元素,我想要动画来查看,但是在他们动画后,我想将它们的动画更多地推迟到CSS(通过改变类)...我发现Velocity留下我所有的动画style=标签中的属性使CSS转换不可能.

我在下面有一个解决方案,但重置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: ""
         });             
    }
});
Run Code Online (Sandbox Code Playgroud)

exe*_*ion 6

通常,您希望动画引擎保持内联样式; 否则最终值将在删除时被样式表覆盖时弹出.

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