Skip to content

Commit c0df9cb

Browse files
committed
docs(readme): update readme and add example.html
1 parent 68dc446 commit c0df9cb

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,30 @@
2323
- [off](#off)
2424

2525
## 基本用法
26+
只需三步即可完成:
27+
1. 引入 css 和 js;
28+
29+
2. 创建一个容器 `div`,注意:这个容器必须是有宽度和高度(如 100% 或者 650px);
30+
```html
31+
<div class="outer-container"></div>
32+
```
33+
34+
3. 准备数据,创建 swiper。
2635
```javascript
2736
var list = [{
37+
content: '<h1>第 0 页</h1>'
38+
}, {
2839
content: '<h1>第 1 页</h1>'
2940
}, {
3041
content: '<h1>第 2 页</h1>'
31-
}, {
32-
content: '<h1>第 3 页</h1>'
33-
}]
42+
}];
3443

3544
var swiper = new Swiper({
36-
container: document.querySelector('body'),
37-
data: list
45+
container: document.querySelector('.outer-container'),
46+
data: list
3847
});
3948
```
49+
具体可以参考 [example.html](https://github.com/fex-team/swiper/blob/master/example.html)
4050

4151
## 数据类型
4252
Swiper 定义了两个数据类型: `Transition``Page``Transition` 用于描述翻页过渡动画,`Page` 用于描述页面。

example.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Swiper Example</title>
8+
<link rel="stylesheet" href="./dist/swiper.css">
9+
<style>
10+
/* 容器需要有宽高 */
11+
html, body, #outer-container {
12+
height: 100%;
13+
width: 100%;
14+
}
15+
</style>
16+
</head>
17+
<body>
18+
<div id="outer-container"></div>
19+
20+
<script src="./dist/swiper.js"></script>
21+
<script>
22+
var list = [{
23+
content: '<h1>第 0 页</h1>'
24+
}, {
25+
content: '<h1>第 1 页</h1>'
26+
}, {
27+
content: '<h1>第 2 页</h1>'
28+
}]
29+
30+
var swiper = new Swiper({
31+
container: document.querySelector('#outer-container'),
32+
data: list
33+
});
34+
</script>
35+
</body>
36+
</html>

0 commit comments

Comments
 (0)