← Torna al blog

Dev Tips

Un trucchetto al giorno leva le complicazioni di torno! Piccole "scorciatoie" che possono facilitare la vita degli sviluppatori e far risparmiare tempo...e righe di codice.

127

Using Intl.RelativeTimeFormat for human-readable time

2023-12-14

1const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
2
3console.log(rtf.format(-1, "day")); // Output: yesterday
4console.log(rtf.format(2, "week")); // Output: in 2 weeks
5
6const rtf2 = new Intl.RelativeTimeFormat("it", { style: "short" });
7
8console.log(rtf2.format(3, "quarter")); // Output: tra 3 trim.
9console.log(rtf2.format(-1, "day")); // Output: 1 g fa
126

One-shot handling of an event

2023-10-29

1// <button id="one-shot-hero-button">Batman! Help me!</button>
2
3const fakeHeroEl = document.getElementById('one-shot-hero-button');
4fakeHeroEl.addEventListener('click', function(event) {
5  console.log('Call me one time and no more!');
6}, {once: true});
7
8fakeHeroEl.click() // Call me one time and no more!
9fakeHeroEl.click() // 
125

Reduce motion sickness with CSS

2023-10-27

1.animation {
2  animation: amazing-animation 1s linear infinite both;
3  background-color: red;
4}
5
6/* Change animation to avoid vestibular motion triggers */
7@media (prefers-reduced-motion) { 
8  .animation {
9    animation: accessible-animation 4s linear infinite both; 
10    background-color: green;
11  }
12}
124

Reduce motion sickness with CSS

2023-10-27

1.animation {
2  animation: amazing-animation 1s linear infinite both;
3  background-color: red;
4}
5/* Change animation to avoid vestibular motion triggers. */
6@media (prefers-reduced-motion) { 	
7  .animation { 	
8    animation: accessible-animation 4s linear infinite both;
9      background-color: green;  
10  } 
11}
123

How to set entire document editable

2021-10-04

1// JS Tip of the Day
2// How to set entire document editable
3
4document.designMode = 'on'; // use it with Developer Tools Console.

Contattaci.

Hai in mente un progetto e vorresti realizzarlo?
Sei interessato a migliorare le competenze del tuo team in ambito di programmazione e sviluppo?
Oppure vuoi semplicemente prendere prendere un caffè con noi e vedere la nostra collezione di Action Figure, allora scrivici tramite questo form.

Se, invece, vuoi far parte del team, guarda le nostre offerte di lavoro.

Questo sito è protetto da reCAPTCHA e si applicano le Norme sulla privacy e i Termini di servizio di Google.