些网站要实现一些弹层效果,经常会有鼠标跟着移动弹层也随之移动的特效,下面来说说这种效果的实现方法!
实现的效果:
下面来看看代码:
html:
css:
js:
HTML 的 tabindex 属性开发过程中一般不会使用到,最近开发中有个需求兼顾富交互,便总结了一下。本篇文章同时收录在我的【前端知识点】中,Github链接请点击阅读原文直达,欢迎 Star
兼容性:Safari不支持!
在我们日常使用网页的过程中,可以通过键盘控制一些元素的聚焦,从而达到便捷访问的目的
element 分为 focusable 和 非focusable ,如果使用了tabindex就可以改变相关的行为
在HTML中有6个元素默认支持聚焦:
以上的元素默认都可以使用 Tab 键,以及 JS focus() 方法聚焦
document.querySelector("a").focus();
使用 tab键 进行聚焦元素时,聚焦的顺序等于元素在代码中的出现先后顺序,当我们进行富交互优化时,就需要用到 tabindex 这个属性来帮助我们进行更好用户体验的优化了
①元素是否能聚焦:通过键盘这类输入设备,或者通过 JS focus() 方法
②元素什么时候能聚焦:在用户通过键盘与页面交互时
通俗来说:就是当用户使用键盘时,tabindex用来定位html元素,即使用tab键时焦点的顺序。
tabindex理论上可以使用在几乎所有元素上
tabindex 有三个值:0,-N(通常是-1),N(正值)
tabindex 决定聚焦顺序
// HTML
<button type="button" tabindex="1">tabindex === 1</button>
<button type="button" tabindex="999">tabindex === 999</button>
<button type="button" tabindex="0">tabindex === 0</button>
// HTML
<button type="button" tabindex="0">tabindex === 0</button>
<button type="button" tabindex="1">tabindex === 1</button>
<button type="button" tabindex="999">tabindex === 999</button>
<button type="button" tabindex="0">tabindex === 0</button>
tabindex 决定是否聚焦
// HTML
<button type="button">未设置tabindex</button>
<button type="button" tabindex="-1">tabindex === -1</button>
<button type="button" tabindex="0">tabindex === 0</button>
<button type="button" tabindex="1">tabindex === 1</button>
tabindex 与JS编程聚焦
// HTML
<button type="button" @click="clickBtn()">点击让DIV聚焦</button>
<div id="FocusDiv" ref="FocusDiv" tabindex="-1">这是一个div</div>
// JS
clickBtn: function() {
document.getElementById('FocusDiv').focus();
}
针对自定义标签进行富交互优化
针对特定节点禁止聚焦操作
复杂列表控制聚焦顺序
现效果:
<script src="https://lf6-cdn-tos.bytescm.com/obj/cdn-static-resource/tt_player/tt.player.js?v=20160723"></script>
实现代码:
*请认真填写需求信息,我们会在24小时内与您取得联系。