4. The Intersection Observer API provides a way to asynchronously
observe changes in the intersection of a target element with an
ancestor element or with a top-level document's viewport.
5. var io = new IntersectionObserver(
entries !=> {
console.log(entries);
}
);
!// Start observing an element
io.observe(element);
!// Stop observing an element
!// io.unobserve(element);
!// Disable IntersectionObserver
!// io.disconnect();
8. ResizeObserver allows you to be notified when an elementâs
content rectangle has changed its size, and react
accordingly.
9. API
var ro = new ResizeObserver( entries !=> {
for (let entry of entries) {
const cr = entry.contentRect;
console.log('Element:', entry.target);
console.log(`Element size: ${cr.width}px x ${cr.height}px`);
console.log(`Element padding: ${cr.top}px ; ${cr.left}px`);
}
});
!// Observe one or multiple elements
ro.observe(someElement);
10. âąObserves the content box.
âąReports dimension and
padding.
âąPolyfills arenât performant as
they rely on polling.
12. âąSingle file for all variations of a font.
âą5 pre-defined axes that can be changed.
âąCustom variable axes can be defined by the designer.
âąAnimation is possible.
âąUse fallback font by changing format.
@font-face {
font-family: "source sans";
src: url(SourceSansVariable.woff2) format("woff2-variations"),
url(SourceSans.woff2) format("woff2"); !/* for older browsers !*/
font-weight: normal;
font-style: normal;
}
19. document.execCommand ?
âą Itâs synchronous.
âą Can only read and write to DOM.
âą Permissions model are lossely defined and vary
across browsers
20. navigator.clipboard.writeText('Text to be copied')
.then(() !=> {
console.log('Text copied to clipboard');
})
.catch(err !=> {
!// This can happen if the user denies clipboard permissions
console.error('Could not copy text: ', err);
});
API
https://jsfiddle.net/r2jurqq7/
29. âą run scripts in background threads.
âą No access to DOM.
âą Communication via postMessage API
30. !// main.js
const myWorker = new Worker('worker.js');
first.onchange = function() {
myWorker.postMessage([first.value,second.value]);
console.log('Message posted to worker');
}
!// worker.js
onmessage = function(e) {
console.log('Message received from main script');
var workerResult = 'Result: ' + (e.data[0] * e.data[1]);
console.log('Posting message back to main script');
postMessage(workerResult);
}
31. https://transform.now.sh
âą Prettier is in worker.
âą Transformations that donât
depend on the DOM are in
worker.
âą Used the package greenlet
to move async functions to
the separate thread.
34. if (navigator.xr) {
navigator.xr.requestDevice()
.then(xrDevice !=> {
!// Advertise the AR/VR functionality to get a user gesture.
})
.catch(err !=> {
if (err.name !!=== 'NotFoundError') {
!// No XRDevices available.
console.error('No XR devices available:', err);
} else {
!// An error occurred while requesting an XRDevice.
console.error('Requesting XR device failed:', err);
}
})
} else{
console.log("This browser does not support the WebXR API.");
}
WebXR Device API
35. WebXR Device API does not provide image rendering features.
Drawing is done using WebGL APIs
40. function onMIDISuccess(midiAccess) {
for (var input of midiAccess.inputs.values())
input.onmidimessage = getMIDIMessage;
}
}
function getMIDIMessage(midiMessage) {
console.log(midiMessage);
}
Listening to input messages
Polyfill: https://github.com/cwilso/WebMIDIAPIShim