javascript 轨道focus.js

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 轨道focus.js相关的知识,希望对你有一定的参考价值。

/*! track-focus v 1.0.0 | Author: Jeremy Fields [jeremy.fields@vget.com], 2015 | License: MIT */
// inspired by: http://irama.org/pkg/keyboard-focus-0.3/jquery.keyboard-focus.js
 
/**
 * Tracks an element is focused via the mouse or keyboard. On mouse focus, adds
 * the mouseClass to the element.
 *
 * Adapted from: https://github.com/ten1seven/track-focus/blob/master/src/javascripts/track-focus.js
 */
 
/*
 &.focus--mouse {
    a,
    button {
        outline: 0 !important;
    }
}
*/
 
export default function trackFocus(el, mouseClass = 'focus--mouse') {
    let usingMouse;
 
    function preFocus(event) {
        usingMouse = event.type === 'mousedown';
    }
 
    function addFocus(event) {
        if (usingMouse) el.classList.add(mouseClass);
    }
 
    function removeFocus(event) {
        el.classList.remove(mouseClass);
    }
 
    function bindEvents() {
        el.addEventListener('keydown', preFocus);
        el.addEventListener('mousedown', preFocus);
        el.addEventListener('focusin', addFocus);
        el.addEventListener('focusout', removeFocus);
    }
 
    function unbindEvents() {
        el.removeEventListener('keydown', preFocus);
        el.removeEventListener('mousedown', preFocus);
        el.removeEventListener('focusin', addFocus);
        el.removeEventListener('focusout', removeFocus);
    }
 
    bindEvents();
 
    return unbindEvents;
}

以上是关于javascript 轨道focus.js的主要内容,如果未能解决你的问题,请参考以下文章

javascript delegation_blur_focus.js

同步视频和音频(最好不使用 JavaScript)

轨道c&;c用于监视Android设备的web应用程序

在碎片MP4中运行的轨道是否必须以关键帧开始?

卫星的轨道形状与

关于卫星运动轨道