Ответ 1
Я нашел решение этой проблемы анимация. Я не знаю, это сработает для вас. Но я нашел несколько coding
проблем в Jsfiddle.
Проблема с первой проблемой.
Вы не применяете правила W3C. button
является закрывающим элементом tag
. Он не закрывает элемент tag
, например <img />
<br />
и т.д.
Проблема второй проблемы.
Вы должны забыть написать свойство position
direction CSS
. position: fixed | absolute | sticky
необходимо установить направление left | right | top | bottom
.
Я много раз тестировал вашу скрипку, почему бы не :active
pseudo-class
не работать после clicked
. Проблема найдена с вашего первого animation
. animation
и bounceInDown
classes
содержат свойство transform
. Ваш animation
не будет работать, пока вы не удалите animation
и bunceInDown
classes
. Поэтому мне нужно написать function
для удаления этих classes
.
$(function(){
$('#button').on('click', function(){
$(this).removeClass('animated bounceInDown');
});
});
Когда я удалил те classes
, я заметил, что кнопка исчезла из-за #button
opacity:
is 0;
. Поэтому мне нужно opacity: 1;
в #button
.
$(function(){
$('#button').on('click', function(){
$(this).addClass('opacity-visible');
});
});
Теперь появилась другая проблема. Проблема первая click
:active
animation
не работает. Из-за первого click
не разрешалось свойство transform
до тех пор, пока animation
classes
не будут удалены. Затем при добавлении animation
classes
необходимо добавить a class
. После добавления нового class
будет работать :active
animation
.
$(function(){
$('#button').on('click', function(){
$(this).addClass('active');
});
});
Теперь нужно установить timeOut
function
для удаления active
class
для button
назад в исходное место для следующего clicked
animation
. Теперь я могу написать все function
вместе.
$(function(){
$('#button').on('click', function(){
$(this).addClass('active opacity-visible');
$(this).removeClass('animated bounceInDown');
setTimeout(function(){
$('#button').removeClass('active');
}, 2000);
});
});
Проверено отрезанное. Надеюсь, это поможет вам выполнить наилучшее решение.
setTimeout( function(){
$("#button").addClass("animated bounceInDown");
}, 1000);
$(function(){
$('#button').on('click', function(){
$(this).addClass('active opacity-visible');
$(this).removeClass('animated bounceInDown');
setTimeout(function(){
$('#button').removeClass('active');
}, 2000);
});
});
*:focus{
outline: none !important;
}
*{
-webkit-tap-highlight-color: rgba(0, 0, 0, 0) !important;
}
#button {
position: fixed;
background-color: green;
border: 2px solid rgba(0, 0, 0, 0.15);
border-radius: 4px;
color: white;
cursor: pointer;
height: 20%;
left: 0;
width: 20%;
top: 0;
opacity: 0;
}
#button:active{
background-color: red;
transform: translateX(50%) !important;
/* animation-name: not_existing_animation; */
}
#button.opacity-visible{
opacity: 1;
transition: transform 0.3s ease-in-out 0s;
}
#button.active{
background-color: black;
transform: translateX(50%) !important;
}
/*!
* animate.css -http://daneden.me/animate
* Version - 3.5.2
* Licensed under the MIT license - http://opensource.org/licenses/MIT
*
* Copyright (c) 2017 Daniel Eden
*/
.bounceInDown {
animation-name: bounceInDown;
opacity: 1!important;
}
.animated {
animation-duration: 1s;
animation-fill-mode: both;
}
@keyframes bounceInDown {
from, 60%, 75%, 90%, to {
animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
}
0% {
opacity: 0;
transform: translate3d(0, -3000px, 0);
}
60% {
opacity: 1;
transform: translate3d(0, 25px, 0);
}
75% {
transform: translate3d(0, -10px, 0);
}
90% {
transform: translate3d(0, 5px, 0);
}
to {
transform: none;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button id="button">Click Me</button>