Whether or not you began with the previous on_____
property or addEventListener
, that occasions drive consumer experiences in trendy JavaScript. Should you’ve labored with occasions, that preventDefault()
and stopPropagation()
are incessantly used to deal with occasions. One factor you in all probability did not know: there is a defaultPrevented
proptery on occasions!
Contemplate the next block of code:
// Particular to a hyperlink const hyperlink = doc.querySelector('#my-link'); hyperlink.addEventListener('click on', e => e.preventDefault()); // A bigger doc scope doc.addEventListener('click on', documentClickHandler); perform documentClickHandler(occasion) { if (occasion.defaultPrevented) {// Utilizing the property // Do one factor if the clicking has been dealt with } else { // In any other case do one thing contemporary } }
When preventDefault
known as on a given occasion, the defaultPrevented
property will get toggled to true
. As a result of occasion propagation, the occasion bubbles upward with this defaultPrevented
worth.
I have been dealing with occasions for 20 years and did not know this property existed till now. What’s nice about defaultPrevented
is that it stays with the occasion with no need to trace monitor it globally!
Responsive and Infinitely Scalable JS Animations
Again in late 2012 it was not straightforward to search out open supply tasks utilizing
requestAnimationFrame()
– that is the hook that permits Javascript code to synchronize with an internet browser’s native paint loop. Animations utilizing this methodology can run at 60 fps and ship incredible…The best way to Create a RetroPie on Raspberry Pi – Graphical Information
In the present day we get to play wonderful video games on our tremendous powered sport consoles, PCs, VR headsets, and even cellular units. Whereas I take pleasure in taking part in new video games as of late, I do lengthy for the retro gaming techniques I had after I was a child: the unique Nintendo…
HTML5’s placeholder Attribute
HTML5 has launched many options to the browser; some HTML-based, some within the type of JavaScript APIs, however all of them helpful. Considered one of my favorites if the introduction of the
placeholder
attribute to INPUT parts. Theplaceholder
attribute reveals textual content in a subject till the…MooTools Zoomer Plugin
I like to go searching the MooTools Forge. As somebody that creates numerous plugins, I get a whole lot of pleasure out of seeing what different builders are creating and probably even how I might enhance them. One nice plugin I’ve discovered is…