Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
些網站要實現一些彈層效果,經常會有鼠標跟著移動彈層也隨之移動的特效,下面來說說這種效果的實現方法!
實現的效果:
下面來看看代碼:
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小時內與您取得聯系。