Bootstrap 5 is a free and open-source CSS framework directed at responsive, mobile-first front-end web development.
Bootstrap 5是一个免费的开源CSS框架,专门用于响应式,移动优先的前端Web开发。
In case you didn't know, Bootstrap 5 alpha has been officially launched. It has removed jQuery as a dependency, has dropped support for Internet Explorer 9 and 10, and brings some awesome updates for the Sass files, markup, and a new Utility API.
如果您不知道, Bootstrap 5 alpha已正式启动 。 它已删除了jQuery的依赖关系,放弃了对Internet Explorer 9和10的支持,并为Sass文件,标记和新的Utility API带来了一些很棒的更新。
This tutorial will show you how to start using VanillaJS instead of jQuery when building websites using the newest version of Bootstrap 5.
本教程将向您展示在使用最新版本的Bootstrap 5构建网站时如何开始使用VanillaJS而不是jQuery。
入门 (Getting started)
You will need to include Bootstrap 5 in your project. There are several ways to do this, but to keep it simple we will include the framework via CDN.
您将需要在项目中包含Bootstrap 5。 有几种方法可以做到这一点,但为简单起见,我们将通过CDN包含该框架。
First of all, let's create a blank index.html
page inside a project folder:
首先,让我们在项目文件夹中创建一个空白的index.html
页面:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootstrap 5 Vanilla JS tutorial by Themesberg</title>
</head>
<body>
</body>
</html>
Include the bootstrap.min.css
stylesheet before the end of your <head>
tag:
在<head>
标记的末尾包括bootstrap.min.css
样式表:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/css/bootstrap.min.css" integrity="sha384-r4NyP46KrjDleawBgD5tp8Y7UzmLA05oM1iAEQ17CSuDqnUK2+k9luXQOfXJCJ4I" crossorigin="anonymous">
Afterwards include the Popper.js library and the main Bootstrap JavaScript file before the end of your <body>
tag:
然后在<body>
标记的末尾包含Popper.js库和Bootstrap主JavaScript文件:
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZ