CSS 属性 overscroll-behavior-y 确定浏览器在达到滚动区域的垂直边界时执行的操作。
您可以参考 overscroll-behavior 以获取详细信息。
可能的值
CSS 属性 overscroll-behavior-y 被定义为下面给出的关键字之一。
- auto - 默认滚动行为是正常的。
- contain − 滚动行为仅在设置值的元素中可见。不对相邻元素设置滚动。
- none - 未看到滚动链接行为。避免了默认的滚动溢出行为。
适用于
所有未替换的块级元素和未替换的内联块元素。
语法
overscroll-behavior-y = contain | auto | none
CSS overscroll-behavior-y - 包含值
以下示例演示了 overscroll-behavior-y: contain 的用法,该 overscroll-behavior-y: contain 将垂直滚动效果设置为包含的和非连续的。
<html>
<head>
<style>
main {
height: 1500px;
width: 100%;
background-color: slateblue;
}
main > div {
height: 300px;
width: 500px;
overflow: auto;
position: relative;
top: 100px;
left: 100px;
overscroll-behavior-y: contain;
}
div > div {
height: 500px;
width: 100%;
background-color: lightblue;
}
p {
padding: 10px;
background-color: rgba(0, 0, 150, 0.2);
margin: 0;
width: 300px;
position: relative;
top: 10%;
left: 2%;
}
</style>
</head>
<body>
<h1>overscroll-behavior-y Property</h1>
<main>
<div>
<div>
<p>
<b>overscroll-behavior-y</b> defines the vertical scrolling area behavior.
The value contain prevents the parent element getting scrolled. Thus preventing the
scrolling chain experience.
</p>
</div>
</div>
</main>
</body>
</html>
CSS overscroll-behavior-y - 自动值
以下示例演示了 overscroll-behavior-y: auto 的使用,该 auto 将滚动效果设置为默认值,其中浏览器决定在到达应用它的元素的垂直边界时滚动父元素。
<html>
<head>
<style>
main {
height: 1500px;
width: 100%;
background-color: slateblue;
}
main > div {
height: 300px;
width: 500px;
overflow: auto;
position: relative;
top: 100px;
left: 100px;
overscroll-behavior-y: auto;
}
div > div {
height: 500px;
width: 100%;
background-color: lightblue;
}
p {
padding: 10px;
background-color: rgba(0, 0, 150, 0.2);
margin: 0;
width: 300px;
position: relative;
top: 10%;
left: 2%;
}
</style>
</head>
<body>
<h1>overscroll-behavior-y Property</h1>
<main>
<div>
<div>
<p>
<b>overscroll-behavior-y: auto</b> defines the vertical scrolling area behavior.
The value auto behaves like the normal scrolling behavior. It is the default value.
</p>
</div>
</div>
</main>
</body>
</html>