cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              html, 
body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, Helvetica Neue, Arial, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
}

.my-custom-class {
  width: 100%;
  text-align: center;
}
            
          
!
            
              const { Component } = React
const { render } = ReactDOM
const { StyleSheet, css } = aphrodite;


const Shake = ({
	h = 5,
	v = 5,
	r = 3,
	dur = 300,
	q = 'infinite',
	tf = 'ease-in-out',
	int = 10,
	max = 100,
	orig = 'center center',
	fixed = false,
	freez = false,
	active = true,
	trigger = ':hover',
	fixedStop = false,
  elem = 'div',
	...props,
}) => {
	const random = (max, min = 0) => {
		return (Math.random() * (max - min) - max / 2);
	};
	
	const doKeyframes = () => {
		// el objecto que iremos llenando
		let kf = {};
		const init = 'translate(0,0) rotate(0)';
		
		// loop con intervalos basados en `int`
		for (let st = int; st <= max; st += int) {
			// Numeros aleatorios en cada keyframe
			const x = random(h);
			const y = random(v);
			const rot = random(r);
			
			kf[`${st}%`] = {
				transform: `translate(${x}px, ${y}px) rotate(${rot}deg)`,
			}
		}
		
		// Init de las transformaciones en 0% y 100%
		kf[`0%`] = kf[`100%`] =  {
			transform: init,
		}
		
		// Init también en caso el `max` < 100
		if (max < 100) {
			kf[`${max}%`] = {
				transform: init,
			}
		}
		
		return kf;
	};

	// Creamos los `@keyframes`
	const keyframes = doKeyframes();
	
  const animAttrs = {
  	animationName: keyframes,
  	animationDuration: `${dur}ms`,
  	animationIterationCount: q,
  };
  
  const styles = StyleSheet.create({
  	base: {
  		display: 'inline-block',
  		transformOrigin: orig,
  	},
  	shake: {
  		...animAttrs,
  	},
  	triggered: {
  		[trigger]: {
  			...animAttrs,
  		},
  	},
  	freez: {
  		animationPlayState: !fixed ? 'paused' : 'running',
  		[trigger]: {
  			animationPlayState: !fixed ? 'running' : 'paused',
  		},
  	},
  	init: {
  		[trigger]: {
  			animation: 'initial',
  		},
  	},
  });
  
  const shouldShakeDefault = fixed || (!fixed && freez);
  const shouldShakeWhenTriggered = !fixed && !freez;
  
  const className = css(
  	shouldShakeWhenTriggered && styles.triggered,
  	shouldShakeDefault && styles.shake,
  	freez && styles.freez,
  	fixed && fixedStop && styles.init,
  );
      
  const Elem = elem;
	
	return (
		<Elem 
      style={props.style}
      className={classNames(props.className, css(styles.base), {
        [className]: active
      })} { ...props }>
  		{ props.children }
  	</Elem>
	);
};

class App extends Component {  
  render () {
    const inputStyle = {
      padding: '.5em 1em',
      margin: '.5em',
    };
    
    const buttonStyle ={
      border: 0,
      padding: '.5em 1em',
      backgroundColor: 'tomato',
      color: 'white',
      margin: '.5em',
    };

    return (
      <div>
        <Shake 
          elem="input"
          trigger=":focus"
          type="email"
          placeholder="lorem@ipsum.com"
          h={0}
          v={50}
          r={0}
          style={inputStyle} />
        <Shake 
          elem="input" 
          type="password"
          trigger=":focus"
          h={50}
          v={0}
          r={0}
          placeholder="Password"
          style={inputStyle} />
        <Shake 
          elem="button" 
          trigger=":focus" 
          dur={2000}
          style={buttonStyle}
          fixed freez>
          Send!
        </Shake>
      </div>
    );
  }
}

render(<App />, 
  document.querySelector("#main"));
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console