liveBook · Manning

CSShake

As explained in Web Components in Action

CSShake is a CSS library that provides animation classes for making elements appear to shake.

CSShake is a CSS library for making elements appear to shake. Add its stylesheet, then add or remove classes on the element that needs visual feedback. section 5.3

A strum-driven animation can be built in a few steps:

  • Calculate a duration from strum power, adding a 250-millisecond minimum. section 5.3
  • Add shake, shake-constant, and shake-horizontal to the target element. section 5.3
  • Add shake-little for weaker strums, then remove all animation classes when the timer expires. section 5.3

Animating a strummed string

A Web Harp string adds the base and directional classes, optionally adds shake-little, and schedules stopStrum() to remove them after the calculated duration. section 5.3

Listing 5.13. Adding CSShake classes to shake our strings when strummed
// file: components/string/string.js

strum(params) {
   if (this.timer) { clearTimeout(this.timer); }

   let dur = params.power * 10 + 250;
   this.classList.add(                                                   #1
       'shake',
       'shake-constant',
       'shake-horizontal');
   if (dur < 500) {
       this.classList.add('shake-little');                               #2
   }
   this.timer = setTimeout( () => this.stopStrum(), dur);
}

stopStrum() {
   this.classList.remove('shake', 'shake-constant', 'shake-horizontal',
     'shake-little');                                                    #3
}

Inspect the complete strum and cleanup implementation, including timer clearing, duration calculation, class changes, and animation removal. section 5.3

How Web Components in Action covers it

How deep it goes
Demonstrates stylesheet inclusion, class toggling, duration calculation, and cleanup without examining library internals.
Examples
Uses a Web Harp string whose shaking varies with strum power and stops through a timer.
What it assumes
Assumes HTML, CSS, JavaScript components, and timers while teaching the library’s class-based usage.
What you can do after
Apply it via CSShake by linking its stylesheet and toggling animation classes on interactive elements.
How it connects
Connects CSS classes with JavaScript timers, Web Components, and interactive DOM elements.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Components in Action. The section links point to the parts of the book it draws on.