cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

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
Loading ..................

Console