在网页设计中,全屏滚动效果可以为页面带来更加生动的展示效果,增强用户体验,同时提升页面美感。而在CSS中,可以通过一些简单的代码实现全屏滚动效果,下面就为大家介绍一下。首先,在HTML标记中,需要创建...
在网页设计中,全屏滚动效果可以为页面带来更加生动的展示效果,增强用户体验,同时提升页面美感。而在CSS中,可以通过一些简单的代码实现全屏滚动效果,下面就为大家介绍一下。
首先,在HTML标记中,需要创建一个容器并将各个页面放入其中,如下所示:
<div class="wrapper">
<section class="section1">页面1</section>
<section class="section2">页面2</section>
<section class="section3">页面3</section>
</div> .wrapper {
position: relative;
width: 100vw;
height: 100vh;
overflow: hidden;
} .section1, .section2, .section3 {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
transition: all 1s ease-in-out;
} document.addEventListener('mousewheel', function(event) {
event.preventDefault();
if (event.deltaY < 0) {
// 向上滚动
currentPage--;
} else {
// 向下滚动
currentPage++;
}
changePage(currentPage);
});
function changePage(pageIndex) {
var wrapper = document.querySelector('.wrapper');
var sections = document.querySelectorAll('section');
if (pageIndex < 0) {
pageIndex = 0;
}
if (pageIndex >= sections.length) {
pageIndex = sections.length - 1;
}
wrapper.style.transform = 'translate3d(0, -' + pageIndex * 100 + '%, 0)';
}