我正在尝试运行一个div滑动到veiw和另一个div滑出veiw的动画,但我认为发生的是代码运行得太快并将显示设置为无,所以你无法看到动画发生在那里无论如何我可以先运行动画,然后设置显示和左值?
<script>
var pagenumon = '1';
function slide(pagenum){
var whichpage = 'page' + pagenum;
var waspage = 'page' + pagenumon;
if(pagenum > pagenumon){
document.getElementById(waspage).style.WebkitAnimation = "transition-left-out 0.5s";
document.getElementById(waspage).style.animation = "transition-left-out 0.5s";
document.getElementById(whichpage).style.WebkitAnimation = "transition-left-in 0.5s"; // Code for Chrome, Safari and Opera
document.getElementById(whichpage).style.animation = "transition-left-in 0.5s";
}else{
document.getElementById(waspage).style.WebkitAnimation = "transition-right-out 0.5s";
document.getElementById(waspage).style.animation = "transition-right-out 0.5s";
document.getElementById(whichpage).style.WebkitAnimation = "transition-right-in 0.5s"; // Code for Chrome, Safari and Opera
document.getElementById(whichpage).style.animation = "transition-right-in 0.5s";
}
if(pagenum == '1'){
document.getElementById('page1').style.left = '0%';
document.getElementById('page1').style.display = 'block';
document.getElementById('page2').style.left = '100%';
document.getElementById('page2').style.display = 'none';
document.getElementById('page3').style.left = '100%';
document.getElementById('page3').style.display = 'none';
document.getElementById('page4').style.left = '100%';
document.getElementById('page4').style.display = 'none';
document.getElementById('page5').style.left = '100%';
document.getElementById('page5').style.display = 'none';
document.getElementById('page6').style.left = '100%';
document.getElementById('page6').style.display = 'none';
}else{
if(pagenum == '2'){
document.getElementById('page1').style.left = '-100%';
document.getElementById('page1').style.display = 'none';
document.getElementById('page2').style.left = '0%';
document.getElementById('page2').style.display = 'block';
document.getElementById('page3').style.left = '100%';
document.getElementById('page3').style.display = 'none';
document.getElementById('page4').style.left = '100%';
document.getElementById('page4').style.display = 'none';
document.getElementById('page5').style.left = '100%';
document.getElementById('page5').style.display = 'none';
document.getElementById('page6').style.left = '100%';
document.getElementById('page6').style.display = 'none';
}else{
if(pagenum == '3'){
document.getElementById('page1').style.left = '-100%';
document.getElementById('page1').style.display = 'none';
document.getElementById('page2').style.left = '-100%';
document.getElementById('page2').style.display = 'none';
document.getElementById('page3').style.left = '0%';
document.getElementById('page3').style.display = 'block';
document.getElementById('page4').style.left = '100%';
document.getElementById('page4').style.display = 'none';
document.getElementById('page5').style.left = '100%';
document.getElementById('page5').style.display = 'none';
document.getElementById('page6').style.left = '100%';
document.getElementById('page6').style.display = 'none';
}else{
if(pagenum == '4'){
document.getElementById('page1').style.left = '-100%';
document.getElementById('page1').style.display = 'none';
document.getElementById('page2').style.left = '-100%';
document.getElementById('page2').style.display = 'none';
document.getElementById('page3').style.left = '-100%';
document.getElementById('page3').style.display = 'none';
document.getElementById('page4').style.left = '0%';
document.getElementById('page4').style.display = 'block';
document.getElementById('page5').style.left = '100%';
document.getElementById('page5').style.display = 'none';
document.getElementById('page6').style.left = '100%';
document.getElementById('page6').style.display = 'none';
}else{
if(pagenum == '5'){
document.getElementById('page1').style.left = '-100%';
document.getElementById('page1').style.display = 'none';
document.getElementById('page2').style.left = '-100%';
document.getElementById('page2').style.display = 'none';
document.getElementById('page3').style.left = '-100%';
document.getElementById('page3').style.display = 'none';
document.getElementById('page4').style.left = '-100%';
document.getElementById('page4').style.display = 'none';
document.getElementById('page5').style.left = '0%';
document.getElementById('page5').style.display = 'block';
document.getElementById('page6').style.left = '100%';
document.getElementById('page6').style.display = 'none';
}else{
if(pagenum == '6'){
document.getElementById('page1').style.left = '-100%';
document.getElementById('page1').style.display = 'none';
document.getElementById('page2').style.left = '-100%';
document.getElementById('page2').style.display = 'none';
document.getElementById('page3').style.left = '-100%';
document.getElementById('page3').style.display = 'none';
document.getElementById('page4').style.left = '-100%';
document.getElementById('page4').style.display = 'none';
document.getElementById('page5').style.left = '-100%';
document.getElementById('page5').style.display = 'none';
document.getElementById('page6').style.left = '0%';
document.getElementById('page6').style.display = 'block';
}}}}}}
window.pagenumon = pagenum;}
</script>
答案 0 :(得分:0)
您无法看到动画,因为无法为display
制作动画。所以你应该做的是:
overflow: hidden
因此不会出现额外的滚动left
设置为100%
或其他display:none
正在应用例如:
setTimeout(function(){
document.getElementById('page6').style.display = 'none';
}, 500)