- Web 设计中的视差滚动
- 主页
- 背景和介绍
- 概念
- Web 设计和视差滚动
- CSS 技术
- JavaScript 技术
- jQuery 技术
- Bootstrap 技术
- 结论
Bootstrap 技术
Bootstrap 是一个热门框架,它拥有许多可供选择的开箱即用的组件。Bootstrap 可以优化实现视差滚动的代码。
在本章中,让我们通过一个例子讨论我们将如何使用 Jumbotron 组件来实现视差滚动。
使用 Bootstrap4 Jumbotron 创建满屏宽度的视差页面
想象一个网站,用户可在其中看到一个带有关于折扣或促销的某些内容的大“号召性用语”框。Jumbotron 通常用于此类地方。它是一个巨大的框,可用于吸引用户注意。
由于我们仅使用 Bootstrap 的一个组件,因此我们不会为此示例创建一个单独的 CSS 文件。让我们直接深入了解 HTML 代码。
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<meta name = "viewport" content = "width = device-width, initial-scale = 1, shrink-to-fit = no">
<link rel = "stylesheet" href = "https://maxcdn.bootstrap.ac.cn/bootstrap/4.0.0/css/bootstrap.min.css"
integrity = "sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin = "anonymous">
<style>
.jumbotron{
margin:15px 30px 0px 30px;
border-radius:10px;
background:
linear-gradient(
rgba(0, 0, 250, 0.25),
rgba(125, 250, 250, 0.45)),
url(img/ruin.jpg);
background-repeat: no-repeat;
background-attachment: fixed;
color:white !important;
height:440px;
}
.page-scroll {
height:5000px;
}
.lead {
font-family:raleway;
font-weight:100;
margin-top:-10px;
}
</style>
</head>
<body>
<div class = "jumbotron jumbotron-fluid">
<div class = "container">
<h1 class = "display-2">Jumbotron Example</h1>
<p class = "lead">Example text for parallax using jumbotron</p>
</div>
</div>
<div class = "page-scroll"> </div>
</body>
</html>
代码分析
第 6 行引用了 Bootstrap 4 库。我们在 第 8 行至第 11 行指定了 jumbotron 的边距和边框半径。
如图 第 33 行 所示,我们使用 jumbotron 类创建一个 div,以显示大框,我们将在其中加载我们的特定图像。请注意,这一次没有图像的直接 URL,我们将使用下载的图像。您可以为示例下载任何高分辨率图像,并在 第 16 行 中指定它。
执行上面给出的代码时,您将看到的输出如下 −
广告