利用html做一个可以炫酷的翻页的页面
时间: 2023-08-04 08:04:06 浏览: 96
html+css翻页动画效果
好的,以下是一个简单的炫酷翻页的 HTML 页面代码示例:
```html
<!DOCTYPE html>
<html>
<head>
<title>Cool Page Flip</title>
<style>
body {
margin: 0;
background-color: #222;
color: #fff;
}
.page {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #444;
transform-origin: 0 50%;
transition: transform 0.8s ease-in-out;
backface-visibility: hidden;
overflow: hidden;
}
.page.active {
transform: perspective(600px) rotateY(0deg);
z-index: 2;
}
.page.inactive {
transform: perspective(600px) rotateY(-180deg);
z-index: 1;
}
.page:first-child {
background-color: #f00;
}
.page:nth-child(2) {
background-color: #0f0;
}
.page:last-child {
background-color: #00f;
}
.page:before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.2);
z-index: -1;
opacity: 0;
transition: opacity 0.5s;
}
.page.active:before {
opacity: 1;
}
.page.inactive:before {
opacity: 0;
}
.page-content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
font-size: 3rem;
font-weight: bold;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}
</style>
</head>
<body>
<div class="page active">
<div class="page-content">Page 1</div>
</div>
<div class="page inactive">
<div class="page-content">Page 2</div>
</div>
<div class="page inactive">
<div class="page-content">Page 3</div>
</div>
<script>
const pages = document.querySelectorAll('.page');
let currentPageIndex = 0;
function showNextPage() {
pages[currentPageIndex].classList.remove('active');
pages[currentPageIndex].classList.add('inactive');
currentPageIndex = (currentPageIndex + 1) % pages.length;
pages[currentPageIndex].classList.remove('inactive');
pages[currentPageIndex].classList.add('active');
}
setInterval(showNextPage, 3000);
</script>
</body>
</html>
```
这段代码会创建一个带有三个页面的 HTML 页面,每个页面的背景颜色都不同,页面之间会以翻页的动画效果切换。可以通过修改页面中的 CSS 样式来改变页面的外观和动画效果,通过修改 JavaScript 代码中的时间间隔来改变页面自动切换的时间。
阅读全文