웹 사이트를 만들 때 페이지가 처음 호출 될 때 CSS 애니메이션이 작동하도록 만들 수 있지만 AJAX 함수가 호출 될 때마다 호출되도록하고 싶습니다. 여기에 여기에AJAX 호출시 CSS 애니메이션이 작동하는 데 문제가 발생했습니다.
function XML(infoId)
{
var xmlHttp = xmlHttpObjCreate();
if (!xmlHttp) {
alert("The browser doesn't support this action.");
return;
}
xmlHttp.onreadystatechange=function() {
if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
elemObj = document.getElementById('textbox');
elemObj.innerHTML = xmlHttp.responseText;
elemObj.className = "bounceInUp";
}
}
// Append GET data to identify which quote we want
var reqURL = "FILE_NAME_HERE_?infoId=" + infoId;
xmlHttp.open("GET", reqURL, true);
xmlHttp.send();
}
작동 기능 여기
부르는의 예입니다 자바 스크립트 XML 호출라는 CSS 애니메이션 코드는 "bounceInUp"
#textbox {
width: 100%;
background-color: transparent;
height: 200px;
color: #0000FF;
font-weight: bold;
font-size: 22px;
overflow: auto;
padding: 10;
-webkit-animation: bounceInUp 1200ms ease-out;
-moz-animation: bounceInUp 1200ms ease-out;
-o-animation: bounceInUp 1200ms ease-out;
animation: bounceInUp 1200ms ease-out;
}
@-webkit-keyframes bounceInUp {
0%, 60%, 75%, 90%, 100% {
-webkit-transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
}
0% {
opacity: 0;
-webkit-transform: translate3d(0, 3000px, 0);
transform: translate3d(0, 3000px, 0);
}
60% {
opacity: 1;
-webkit-transform: translate3d(0, -20px, 0);
transform: translate3d(0, -20px, 0);
}
75% {
-webkit-transform: translate3d(0, 10px, 0);
transform: translate3d(0, 10px, 0);
}
90% {
-webkit-transform: translate3d(0, -5px, 0);
transform: translate3d(0, -5px, 0);
}
100% {
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
}
@keyframes bounceInUp {
0%, 60%, 75%, 90%, 100% {
-webkit-transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
}
0% {
opacity: 0;
-webkit-transform: translate3d(0, 3000px, 0);
transform: translate3d(0, 3000px, 0);
}
60% {
opacity: 1;
-webkit-transform: translate3d(0, -20px, 0);
transform: translate3d(0, -20px, 0);
}
75% {
-webkit-transform: translate3d(0, 10px, 0);
transform: translate3d(0, 10px, 0);
}
90% {
-webkit-transform: translate3d(0, -5px, 0);
transform: translate3d(0, -5px, 0);
}
100% {
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
}
.bounceInUp {
-webkit-animation-name: bounceInUp;
animation-name: bounceInUp;
}
I 임 모든 코드에 대해 사과해야하지만 누군가가 나를 도와 주어야 할 모든 것이 여기에 있는지 확인하고 싶습니다. 따라서 CSS 기능이 호출 될 때가 아니라 페이지가 처음로드 될 때만 css 애니메이션이 실행됩니다.
좋아, 그래서 당신의 단순화 된 방법을 생각하고있어. #textbox에서 애니메이션 속성을 제거했습니다. 내가 선택한 요소에 .bounceInUp 클래스를 적용하고 제거하는 방법은 어떻게됩니까? – Solstice
예, 작동합니다. 또한 classList.remove 및 classList.add 사용에 대한 Martin Cortez의 대답을 참조하십시오. 클래스에 여러 클래스 이름이 적용된 경우 제거 할 className 만 제거해야합니다. –