在构建我的网站时,我想添加一个使用 Javascript 进行动画处理的图像。我将 iFrame 与另一个 HTML 文档链接,然后一切正常,但我想将它循环进出。我在谷歌上搜索了它,但每个结果都带有 Youtube 嵌入的视频,谁能告诉我如何循环这个 iFrame。这是代码:
const banner = document.getElementsByClassName('banner')[0];
const blocks = document.getElementsByClassName('blocks');
for (var i = 1; i < 400; i++) {
banner.innerHTML += "<div class='blocks'></div>";
const duration = Math.random() * 5;
blocks[i].style.animationDuration = 2 + duration + 's';
blocks[i].style.animationDelay = duration + 's';
}
const section = document.querySelector('section');
setTimeout(function() {
section.classList.add('active')
}, 13000); //14000 adds class active after 13s (13000ms)
@import url('https://fonts.googleapis/css?family=Poppins:400,500,600,700,800,900&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body {
background: #141414;
}
section {
position: relative;
width: 100%;
height: 100vh;
transform-style: preserve-3d;
perspective: 500px;
}
section h2 {
position: relative;
width: 100%;
height: 100vh;
text-align: center;
line-height: 100vh;
font-size: 10vw;
color: white;
font-weight: 700;
}
.banner {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
overflow: hidden;
display: flex;
flex-wrap: wrap;
}
.banner .blocks {
position: relative;
display: block;
width: 5vw;
height: 5vh;
background: transparent;
animation: animate 2s ease-in-out forwards;
animation-delay: 1s;
}
@keyframes animate {
0% {
transform: translateZ(2000px);
background: url(./Images/medic\ 3.jpg);
background-repeat: center;
background-attachment: fixed;
background-size: cover;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}
100% {
transform: translateZ(0px);
background: url(./Images/medic\ 3.jpg);
background-repeat: center;
background-attachment: fixed;
background-size: cover;
border: 1px solid rgba(0, 0, 0, .1);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0);
}
}
section.active .banner .blocks {
animation: animateTwo 2s ease-in-out forwards;
background: url(./Images/medic\ 3.jpg);
background-repeat: center;
background-attachment: fixed;
background-size: cover;
border: 1px solid rgba(0, 0, 0, .1);
}
@keyframes animateTwo {
0% {
transform: translateZ(0px);
background: url(./Images/medic\ 3.jpg);
background-repeat: center;
background-attachment: fixed;
background-size: cover;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}
100% {
transform: translateZ(2000px);
background: url(./Images/medic\ 3.jpg);
background-repeat: center;
background-attachment: fixed;
background-size: cover;
border: 1px solid rgba(0, 0, 0, .1);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0);
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="styles2.css">
</head>
<body>
<section>
<h2>JS Animation</h2>
<div class="banner">
<div class="blocks"></div>
</div>
</section>
<script src="./iframe.js"></script>
</body>
</html>