简体   繁体   English

我还应该在VueJS中使用jQuery来制作动画吗?

[英]Should I still use jQuery to animations in VueJS?

I currently have this piece of code inside my methods object in a component: 我目前在组件中的方法对象中有这段代码:

startImageAnimation() {
    $('.splash-image').fadeIn(1400, () => {
        setTimeout(function() {
            $('.splash-image').fadeOut(1400, () => {
                setTimeout(() => {
                    $('.splash-screen').fadeOut(600);
                });
            });
        }, 1000);
    });
},

I really tried to figure a way to it using Vue transitions, but it just looks waaaaay too hard for something this simple to do using jQuery. 我真的试图用Vue转换来找到它的方法,但是对于使用jQuery这么简单的事情,它看起来太难了。

The real question here is: should I still code like this or should I take a different approach in these situations? 这里真正的问题是:我是否还应该像这样编码,还是应该在这些情况下采用不同的方法? The same for things like jQuery animate() or any other methods that jQuery makes a lot easier to do than with pure JS. 对于像jQuery animate()或jQuery比使用纯JS更容易做的任何其他方法这样的事情也是如此。

Thanks! 谢谢!

I personally prefer to animate not the element directly, but properties connected with it. 我个人更喜欢不直接动画元素,而是与它相关的属性。 For example, I might use such a piece of code: 例如,我可能会使用这样一段代码:

<div class="splash-screen" :style={opacity: splashOpacity}>

where splashOpacity is a property of the object, returned by data method of Vue component. 其中splashOpacity是对象的属性,由Vue组件的data方法返回。 And then I smoothly change splashOpacity , either vie setInterval or some sort of library like Greensock . 然后我顺利地改变splashOpacity ,或者改变setInterval或者像Greensock这样的某种库。 Short example: 简短的例子:

data () {
    return {
       splashOpacity: 0 
    }
},

startImageAnimation () {
    TweenLite.to(this, 1, {
       splashOpacity: 1
    }); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM