[英]Two animations using css, javascript, two buttons onclick()
I want to create two animations in css.我想在 css 中创建两个动画。 In my project, I use two button, one object.
在我的项目中,我使用两个按钮,一个对象。 I care, that the first button is being clicked, the first animation on the object is being run.
我关心的是,第一个按钮被点击,对象上的第一个动画正在运行。
I know, what I should do, when I have one button and one animation, but I do not know how to solve problem with two different animations on the same object.我知道,当我有一个按钮和一个动画时我应该做什么,但我不知道如何解决同一对象上两个不同动画的问题。
Edit 3. I find problem!编辑 3. 我发现问题!
Does this meet your requirements?这符合您的要求吗?
let btn_a = document.getElementById('a') let btn_b = document.getElementById('b') let btn_c = document.getElementById('c') let div = document.getElementById('obj') btn_a.addEventListener('click', function() { div.className = 'anim-a' }) btn_b.addEventListener('click', function() { div.className = 'anim-b' }) btn_c.addEventListener('click', function() { $('#obj').animate({}, function(){ $('#obj').css({transform: 'rotate(30deg) translate(200px)'}) }) })
div { background-color: pink; width: 100px; transition: all linear 0.5s; } .anim-a { background-color: yellowgreen; width: 150px; } .anim-b { background-color: grey; width: 200px; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id='obj'>animated</div> <button id='a'>anim-a</button> <button id='b'>anim-b</button> <button id='c'>anim-c</button>
EDIT编辑
Without css fields, assuming that you're using jQuery, you can use .animate()
.如果没有 css 字段,假设您使用的是 jQuery,则可以使用
.animate()
。 However, .animate()
won't take transform
as its property.但是,
.animate()
不会将transform
作为其属性。 We'll do this in the callback.我们将在回调中执行此操作。
btn_c.addEventListener('click',function() {
$('#obj').animate({}, function(){
$('#obj').css({transform: 'rotate(30deg)'})
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.