- Notifications
You must be signed in to change notification settings - Fork 22.7k
/
Copy pathindex.md
165 lines (131 loc) · 3.18 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
---
title: scroll-behavior
slug: Web/CSS/scroll-behavior
page-type: css-property
browser-compat: css.properties.scroll-behavior
---
{{CSSRef}}
The **`scroll-behavior`**[CSS](/en-US/docs/Web/CSS) property sets the behavior for a scrolling box when scrolling is triggered by the navigation or CSSOM scrolling APIs.
{{InteractiveExample("CSS Demo: scroll-behavior")}}
```css interactive-example-choice
scroll-behavior: auto;
```
```css interactive-example-choice
scroll-behavior: smooth;
```
```htmlinteractive-example
<section id="default-example">
<div class="container">
<p class="nav">
Scroll to:
<a href="#pageA">A</a>
<a href="#pageB">B</a>
<a href="#pageC">C</a>
</p>
<scroll-container id="example-element">
<scroll-page id="pageA">A</scroll-page>
<scroll-page id="pageB">B</scroll-page>
<scroll-page id="pageC">C</scroll-page>
</scroll-container>
</div>
</section>
```
```css interactive-example
.container {
flex-direction: column;
}
.nava {
color: #009e5f;
}
scroll-container {
border: 1pxsolidblack;
display: block;
height: 200px;
overflow-y: scroll;
width: 200px;
}
scroll-page {
align-items: center;
display: flex;
font-size: 5em;
height: 100%;
justify-content: center;
}
```
Note that any other scrolls, such as those performed by the user, are not affected by this property. When this property is specified on the root element, it applies to the viewport instead. This property specified on the `body` element will _not_ propagate to the viewport.
User agents are allowed to ignore this property.
## Syntax
```css
/* Keyword values */
scroll-behavior: auto;
scroll-behavior: smooth;
/* Global values */
scroll-behavior: inherit;
scroll-behavior: initial;
scroll-behavior: revert;
scroll-behavior: revert-layer;
scroll-behavior: unset;
```
The `scroll-behavior` property is specified as one of the keyword values listed below.
### Values
- `auto`
- : The scrolling box scrolls instantly.
- `smooth`
- : The scrolling box scrolls in a smooth fashion using auser-agent-defined easing function over auser-agent-defined period of time. User agents should follow platform conventions, if any.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting smooth scroll behavior
#### HTML
```html
<nav>
<a href="#page-1">1</a>
<a href="#page-2">2</a>
<a href="#page-3">3</a>
</nav>
<div class="scroll-container">
<div class="scroll-page" id="page-1">1</div>
<div class="scroll-page" id="page-2">2</div>
<div class="scroll-page" id="page-3">3</div>
</div>
```
#### CSS
```css
a {
display: inline-block;
width: 50px;
text-decoration: none;
}
nav,
.scroll-container {
display: block;
margin: 0auto;
text-align: center;
}
nav {
width: 339px;
padding: 5px;
border: 1pxsolidblack;
}
.scroll-container {
width: 350px;
height: 200px;
overflow-y: scroll;
scroll-behavior: smooth;
}
.scroll-page {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
font-size: 5em;
}
```
#### Result
{{ EmbedLiveSample("Setting_smooth_scroll_behavior", "100%", 250) }}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}