全屏滚动(Fullpage Scrolling)是一种网页设计技术,它允许用户在单个页面上通过滚动来浏览多个全屏页面。每个全屏页面可以包含不同的内容和设计元素,从而提供一种独特的视觉体验。
使用jQuery实现全屏滚动的基本步骤如下:
<section>
标签中。<section>
的高度为100vh,宽度为100%,并设置背景颜色或图片。<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fullscreen Scroll</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<section class="section" style="background-color: #f06;">
<h1>Section 1</h1>
</section>
<section class="section" style="background-color: #0f6;">
<h1>Section 2</h1>
</section>
<section class="section" style="background-color: #06f;">
<h1>Section 3</h1>
</section>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="script.js"></script>
</body>
</html>
html, body {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
}
.section {
height: 100vh;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
font-size: 2em;
}
$(document).ready(function() {
$('body, html').animate({
scrollTop: 0
}, 0);
$('html, body').on('scroll', function() {
let scrollTop = $(this).scrollTop();
let sections = $('.section');
sections.each(function(index) {
if (scrollTop >= index * $(window).height() && scrollTop < (index + 1) * $(window).height()) {
// Highlight the current section
sections.removeClass('active');
$(this).addClass('active');
}
});
});
});
通过以上步骤和示例代码,你可以实现一个基本的全屏滚动效果。根据具体需求,可以进一步优化和扩展功能。
领取专属 10元无门槛券
手把手带您无忧上云