Shake Effect
Quick attention/error shake animation. Perfect for form validation feedback and drawing attention to important elements.

See Also

All JavaScript Effects Breathe Pulse Scribe Reveal Scramble Counter Ripple Twinkle

Domma.effects.shake()

The shake() effect applies a quick shake animation to draw attention or signal an error. Supports horizontal, vertical, and both directions with configurable intensity and iterations.

// Shake an invalid input
Domma.effects.shake('#email-input');

// Vertical shake with callback
Domma.effects.shake('.alert', {
  direction: 'vertical',
  intensity: 4,
  iterations: 2,
  onComplete: () => console.log('Shake done')
});

// Intense shake
Domma.effects.shake('.error-box', {
  intensity: 12,
  duration: 800,
  direction: 'both'
});

Demo: Shake Directions

Three shake directions: horizontal, vertical, and both axes simultaneously.

Horizontal
Vertical
Both
Domma.effects.shake('#el', { direction: 'horizontal' }); // Default
Domma.effects.shake('#el', { direction: 'vertical' });
Domma.effects.shake('#el', { direction: 'both' });

Demo: Intensity Levels

Different shake intensities from subtle to extreme.

Subtle (2px)
Normal (6px)
Intense (12px)
Domma.effects.shake('#el', { intensity: 2 });   // Subtle
Domma.effects.shake('#el', { intensity: 6 });   // Normal (default)
Domma.effects.shake('#el', { intensity: 12 });  // Intense

Demo: Form Validation

Shake invalid form inputs to draw attention. Try submitting with an empty or invalid email.

$('#submit').on('click', () => {
  const email = $('#email').val();
  const isValid = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);

  if (!isValid) {
    $('#email').addClass('invalid');
    Domma.effects.shake('#email', {
      intensity: 4,
      duration: 400,
      onComplete: () => {
        // Remove invalid state after delay
        setTimeout(() => $('#email').removeClass('invalid'), 2000);
      }
    });
  }
});

Demo: Multiple Iterations

Repeat the shake cycle multiple times for persistent emphasis.

Shake Me!
Domma.effects.shake('#el', { iterations: 1 }); // Default
Domma.effects.shake('#el', { iterations: 2 });
Domma.effects.shake('#el', { iterations: 3 });

Demo: Staggered Shake

Shake multiple elements with a cascading delay.

Item 1
Item 2
Item 3
Item 4
Domma.effects.shake('.item', {
  stagger: 100,
  intensity: 5,
  direction: 'horizontal'
});

Options Reference

OptionTypeDefaultDescription
intensitynumber6Shake distance in pixels
durationnumber500Total shake duration in ms
directionstring'horizontal''horizontal', 'vertical', 'both'
easingstring'ease-in-out'CSS easing function
iterationsnumber1Number of shake cycles
staggernumber0Delay between elements (ms)
respectMotionPreferencebooleantrueHonour prefers-reduced-motion
onCompletefunctionnullCallback when shake completes