原生JS实现翻书翻页动画效果
作者:页面旅途时间:2026-10-24 17:03:55浏览:255
本文分享一个使用原生JavaScript配合CSS3实现的翻书翻页动画效果。通过简单的HTML结构和JavaScript逻辑,无需依赖第三方库即可实现逼真的页面翻转交互体验,适合前端开发者参考学习。
原生JS翻书特效实现
本文分享一个使用原生JavaScript实现的翻书动画效果,具体视觉呈现如下:

完整的实现代码已提供,开发者可直接复制使用。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>原生JS实现翻书特效</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
list-style: none;
}
#btn {
width: 50px;
height: 40px;
line-height: 40px;
position: relative;
left: 50%;
margin-left: -25px;
top: 100px;
}
#book {
width: 600px;
height: 400px;
position: absolute;
left: 50%;
top: 50%;
margin: -200px 0 0 -300px;
border: 1px solid black;
/* 第一个封面 */
background: url(images/0.jpg);
}
#rightPage {
width: 50%;
height: 100%;
position: absolute;
left: 50%;
z-index: 2;
transition: 0.5s;
transform: perspective(800px) rotateY(0px);
transform-origin: left center;
background: black;
transform-style: preserve-3d;
}
#rightPage #topNode {
position: absolute;
width: 100%;
height: 100%;
/* 第一个封面 */
background: url(images/0.jpg) 300px 0;
transform: translateZ(1px);
}
#rightPage #bottomNode {
position: absolute;
width: 100%;
height: 100%;
/* 第三个封面 */
background: url(images/2.jpg) 0 0;
/*scaleX将翻书镜像后的图像还原镜像*/
transform: translateZ(-1px) scaleX(-1);
}
#rightOtherPage {
position: absolute;
left: 50%;
height: 100%;
width: 50%;
/* 第三个封面 */
background: url(images/2.jpg) 300px 0;
z-index: 1;
}
</style>
</head>
<body>
<input type='button' value='下一页' id='btn'>
<div id='book'>
<div id='rightPage'>
<div id='topNode'></div>
<div id='bottomNode'></div>
</div>
<div id='rightOtherPage'></div>
</div>
<script type="text/javascript">
var index = 0;
var flag = false;
btn.onclick = function () {
if (flag) return;
flag = true;
index++;
rightPage.style.transition = '0.5s';
rightPage.style.transform = 'perspective(800px) rotateY(-180deg)';
setTimeout(function () {
// 翻页后瞬间更换下一页的背景
book.style.backgroundImage = 'url(images/' + (index % 2 + 1) + '.jpg)';
// 让翻页瞬间回去
rightPage.style.transition = '0s';
rightPage.style.transform = 'perspective(800px) rotateY(0deg)';
// 更换翻页纸正面背景
topNode.style.backgroundImage = 'url(images/' + (index % 2 + 1) + '.jpg)';
// 更换翻页纸背面背景
bottomNode.style.backgroundImage = 'url(images/' + ((index + 1) % 2 + 1) + '.jpg)';
// 更换翻页后的纸背景
rightOtherPage.style.backgroundImage = 'url(images/' + ((index + 1) % 2 + 1) + '.jpg)';
flag = false;
}, 500);
};
</script>
</body>
</html>
以上就是本文的全部内容,希望能为各位的学习带来帮助,同时也欢迎大家继续支持本站。
作者最新文章
JS监听滚动事件:回到顶部按钮的显示与隐藏逻辑
2026-11-05 16:19:37
JavaScript怎么读写LocalStorage与SessionStorage
2026-11-05 15:40:11
anime.js 与 GSAP 对比:轻量级项目该怎么选择动画库
2026-11-05 11:24:55
flv.js 与 hls.js 在直播场景下的选型对比
2026-11-05 08:18:52
JavaScript能做什么?前端开发中的作用与应用场景解析
2026-11-04 23:17:54
