css3中的scroll-behavior属性
scroll-behavior属性
当用户手动导航或者 CSSOM scrolling API 触发滚动操作时,CSS 属性 scroll-behavior 为一个滚动框指定滚动行为,当用户通过鼠标滑轮滚动或者手机触屏滚动,不受这个属性的影响。在根元素中指定这个属性时,它反而适用于视窗。
scroll-behavior属性包括: smooth | auto;
auto: 默认值,表示滚动框立即滚动到指定位置。 smooth 表示允许滚动时采用平滑过渡,而不知直接滚动到相应位置,最常见的比如回到顶部按钮和锚点。
scroll-behavior浏览器支持情况:

- 通过锚点的方式实现,代码如下:
html代码:<div class="tab-box">
<div class="tab-t">
<a class="labels" href="#tab1">选项卡1</a>
<a class="labels" href="#tab2">选项卡2</a>
<a class="labels" href="#tab3">选项卡3</a>
</div>
<div class="tab-body">
<div class="content" id="tab1">
<p>我是选项卡1</p>
</div>
<div class="content" id="tab2">
<p>我是选项卡2</p>
</div>
<div class="content" id="tab3">
<p>我是选项卡3</p>
</div>
</div>
</div>less代码:
.tab-box{
margin: 20px;
.labels {
width: 100px;
margin-right: -1px;
border: 1px solid #ccc;
border-bottom:;
padding-top: 5px;
padding-bottom: 5px;
background-color: #eee;
text-align: center;
display: inline-block;
text-decoration: none;
color:#555;
}
.tab-body {
height: 200px;
border: 1px solid #ccc;
scroll-behavior: smooth;
overflow: hidden;
.content {
height: 100%;
padding: 0 20px;
position: relative;
overflow: hidden;
input {
position: absolute;
top:;
height: 100%;
width: 100px;
border:;
padding:;
margin:;
clip: rect(0 0 0 0);
}
}
}
} - 通过label和表单元素得到焦点的特性实现,代码如下:
html代码:
<div class="tab-box">
<div class="tab-t">
<label class="label" for="tab1">选项卡1</label>
<label class="label" for="tab2">选项卡2</label>
<label class="label" for="tab3">选项卡3</label>
</div>
<div class="tab-body">
<div class="content"><input id="tab1" type="text">
<p>我是选项卡1</p>
</div>
<div class="content"><input id="tab2" type="text">
<p>我是选项卡2</p>
</div>
<div class="content"><input id="tab3" type="text">
<p>我是选项卡3</p>
</div>
</div>
</div>less代码:
.tab-box{
margin: 20px;
.label {
width: 100px;
margin-right: -1px;
border: 1px solid #ccc;
border-bottom:;
padding-top: 5px;
padding-bottom: 5px;
background-color: #eee;
text-align: center;
display: inline-block;
}
.tab-body {
height: 200px;
border: 1px solid #ccc;
scroll-behavior: smooth;
overflow: hidden;
.content {
height: 100%;
padding: 0 20px;
position: relative;
overflow: hidden;
input {
position: absolute;
top:;
height: 100%;
width: 100px;
border:;
padding:;
margin:;
clip: rect(0 0 0 0);
}
}
}
}
css3中的scroll-behavior属性的更多相关文章
- CSS3中transform几个属性值的注意点
transform(变形)是CSS3中的元素的属性,transform的属性值主要包括旋转rotate.扭曲skew.缩放scale和移动translate以及矩阵变形matrix 基本用法可以参考文 ...
- css3新增属性有哪些?css3中常用的新增属性总结
css3新增属性有哪些?来提问这个问题的人都应该知道css3是css的升级版本,那么,css3既然是升级版本,自然是会新增一些属性,接下来本篇文章将给大家介绍关于css3中常用的新增属性. 一.css ...
- css3中的zoom元素属性值测试
在样式表里头看到zoom:1的设置,很是好奇就去找了一些资料发现关于这个的讲述还是比较少. 理论知识 语法: zoom:normal | <number> | <percentage ...
- CSS3中盒子的box-sizing属性
box-sizing 属性 box-sizing 属性用来改变默认的 CSS盒模型 对元素宽高的计算方式.这个属性可以用于模拟那些非正确支持标准盒模型的浏览器的表现. box-sizing:conte ...
- 第92天:CSS3中颜色和文本属性
一.颜色的表示方式 1. rgba(255,0,0,0.1) rgba是代表Red(红色) Green(绿色) Blue(蓝色)和 Alpha透明度.虽然它有的时候被描述为一个颜色空间 新增了RGB ...
- CSS3中的动画效果记录
今天要记录的是CSS3中的三种属性transform.transition以及animation,这三个属性大大提升了css处理动画的能力. 一.Transform 变形 CSS中transform ...
- CSS3中DIV水平垂直居中-2(3)
用到CSS3中display的新属性. HTML <div class="parent"> </div> CSS html,body{ width: 100 ...
- CSS3让文本自动换行——word-break属性
1.依靠浏览器让文本自动换行 浏览器本身都自带着让文本自动换行的功能. 2.指定自动换行的处理方法 在CSS3中,可以使用word-break属性来自己决定自动换行的处理方法. div{ word-b ...
- CSS3中的变形与动画(二)
CSS3动画 过渡属性transiton-property 早期在Web中要实现动画效果,都是依赖于JavaScript或Flash来完成.但在CSS3中新增加了一个新的模块transition,它可 ...
- 利用ie的behavior属性兼容css3的一些属性
behavior是从Internet Explorer 5开始引入的,是一种通过使用 CSS 向 HTML 元素添加行为的方法. 但是只有 Internet Explorer 支持 behavior ...
随机推荐
- geometry_msgs的ros message 类型赋值
test_custom_particles.cpp // // Created by gary on 2019/8/27. // #include <ros/ros.h> #include ...
- spring启动图案修改(纯属好玩)
在resource目录下新建banner.txt(与application.properties或者application.yml同级) 在里面随便写自己的汉字图案就行了,比如我的: _ooOoo_ ...
- Android学习电子书
- 在Ubuntu上安装LAMP(Apache、Mysql、Php)
原文地址:https://howtoubuntu.org/how-to-install-lamp-on-ubuntu Ubuntu有很多工具可以帮助我们一键配置LAMP环境,比如tasksel,但这些 ...
- Python错误提示:[Errno 24] Too many open files的分析与解决
背景 最近在工作中发现了一个错误,在执行多线程扫描脚本的时候频繁出现下面这个错误 HTTPConnectionPool(host=‘t.tips', port=80): Max retries exc ...
- RPC_简洁版
1.定义服务接口 public interface RpcService { int printHello(int msg); } 2.定义服务接口实现类 public class RpcInterf ...
- canvas 操作像素 反相
代码实例: <!DOCTYPE html> <html> <head> <style> canvas{ background:#eee; } </ ...
- cassandra集群
cassandra是分布式数据库属于nosql,用于处理大量商用服务器上的大量数据,提供高可用性,无单点故障. Cassandra在其节点之间具有对等分布式系统,并且数据分布在集群中的所有节点之间. ...
- 使用axios上传文件到阿里云对象文件存储服务器oss
背景 OSS可用于图片.音视频.日志等海量文件的存储.各种终端设备.Web网站程序.移动应用可以直接向OSS写入或读取数据.OSS支持流式写入和文件写入两种方式.使用阿里云oss做文件存储的时候,不可 ...
- 前端每日实战:72# 视频演示如何用纯 CSS 创作气泡填色的按钮特效
效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/eKqZjy 可交互视频 此视频是可 ...