火影忍者网页设计html,html+css+js实现火影背景切换登录页面
时间: 2024-01-06 19:04:15 浏览: 32
好的,为了实现火影忍者的背景切换登录页面,我们需要用到HTML、CSS和JS。首先,我们需要准备好背景图片,这里我选择了几张火影忍者的图片。
接下来,我们可以开始编写代码了。
HTML代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>火影忍者登录页面</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<div id="bg-img"></div>
<div class="container">
<form>
<h1>火影忍者登录</h1>
<input type="text" placeholder="用户名">
<input type="password" placeholder="密码">
<button type="submit">登录</button>
</form>
</div>
</body>
</html>
```
我们在页面中添加了一个id为“bg-img”的div,用来显示背景图片。我们还添加了一个class为“container”的div,用来包含登录表单。
CSS代码:
```css
body {
margin: 0;
padding: 0;
background-color: #000;
}
#bg-img {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
background-size: cover;
background-position: center;
animation: bg-slide 20s infinite;
}
@keyframes bg-slide {
0% {
background-image: url("bg1.jpg");
}
25% {
background-image: url("bg2.jpg");
}
50% {
background-image: url("bg3.jpg");
}
75% {
background-image: url("bg4.jpg");
}
100% {
background-image: url("bg5.jpg");
}
}
.container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: rgba(255, 255, 255, 0.8);
padding: 30px;
border-radius: 5px;
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.3);
}
h1 {
text-align: center;
font-size: 32px;
margin-bottom: 20px;
}
input {
display: block;
width: 100%;
padding: 10px;
margin-bottom: 20px;
font-size: 16px;
border: none;
border-radius: 5px;
box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.3);
}
button {
display: block;
width: 100%;
padding: 10px;
background-color: #c9302c;
color: #fff;
font-size: 16px;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #a52725;
}
```
在CSS中,我们设置了背景图片的位置、大小和动画。我们使用了@keyframes来实现背景图片的切换,每25%的时间显示一张不同的图片。我们还设置了登录表单的样式,包括位置、颜色、边框和阴影等。
JS代码:
```javascript
window.onload = function() {
var bgImg = document.getElementById("bg-img");
var bgImgs = ["bg1.jpg", "bg2.jpg", "bg3.jpg", "bg4.jpg", "bg5.jpg"];
var index = 0;
setInterval(function() {
index++;
if (index == bgImgs.length) {
index = 0;
}
bgImg.style.backgroundImage = "url(" + bgImgs[index] + ")";
}, 20000);
}
```
在JS中,我们使用了一个定时器来实现背景图片的切换。我们设置了一个数组来存储背景图片的路径,然后每隔20秒就切换一次背景图片。
最后,我们将HTML、CSS和JS保存到同一个文件夹中,然后我们就可以在浏览器中打开这个文件来查看火影忍者的背景切换登录页面了。