Skip to content

Some Knowledge Points About Developing Keyboard js

Junjia Ni edited this page Sep 27, 2016 · 1 revision

Some Website:

javascript multiple keys pressed at once

preventDefault vs. stopPropagation vs. stopImmediatePropagation

前端工程师手册/单例模式

shichuan/javascript-patterns

The Singleton Pattern

JavaScript Madness: Keyboard Events

Q&&A

Q: how to click link below a higher z-index div?

A: pointer-events: none

Reference

Q: how to detecting focus of a browser window?

A:

function onBlur() {
	document.body.className = 'blurred';
};
function onFocus(){
	document.body.className = 'focused';
};

if (/*@cc_on!@*/false) { // check for Internet Explorer
	document.onfocusin = onFocus;
	document.onfocusout = onBlur;
} else {
	window.onfocus = onFocus;
	window.onblur = onBlur;
}

Reference

Q: Difference between document.addEventListener and window.addEventListener?

A: The document and window are different objects and they have some different events.

Reference

Q: How to trigger an event after using event.preventDefault() ?

A: You can trigger or dispatchEvent again (You can see Creating and triggering events). Or you can judge it before preventDefault

Reference

Clone this wiki locally