Pen Settings

HTML

CSS

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.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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.

+ add another resource

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="app"></div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Courier+Prime:wght@700&display=swap');

html, body
{
	font-family: 'Courier Prime', monospace;
	
	width: 100%;
	height: 100%;
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	margin: 0;
	padding: 0;
	
	background-color: #fff;
	background: linear-gradient(0deg, rgba(0, 0, 200, 0.1) , rgba(0, 0, 200, 0) ),
				linear-gradient(120deg, rgba(50, 150, 100, 0.2) , rgba(0, 0, 100, 0) );
				//linear-gradient(240deg, rgba(150, 50, 50, 0.3) , rgba(0, 0, 200, 0) );
	
	overflow: hidden;
}

.container
{
	position: relative;

	width: 80vmin;
	height: 80vmin;
	
	max-height: 600px;
	max-width: 600px;
	
	overflow: hidden;
	border-radius: 20px;
	
	

}

.shadow
{
	box-shadow:
	  0 2.8px 2.2px rgba(0, 0, 0, 0.02),
	  0 6.7px 5.3px rgba(0, 0, 0, 0.028),
	  0 12.5px 10px rgba(0, 0, 0, 0.035),
	  0 22.3px 17.9px rgba(0, 0, 0, 0.042),
	  0 41.8px 33.4px rgba(0, 0, 0, 0.05),
	  0 100px 80px rgba(0, 0, 0, 0.07)
	;
}

#app
{
	position: relative;
}

.image, .tabs
{
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	
	svg
	{
		width: 100%;
	}
}

image
{
	pointer-events: none;
}

.border
{
	fill: white;
	fill-opacity: 0;
	stroke: white;
	stroke-width: 2;
	stroke-opacity: 0.7;
	cursor: pointer;
	
	&:hover
	{
		stroke-opacity: 1;
	}
}

text
{
	fill: white;
	font-size: 28px;
	stroke: black;
	stroke-width: 1;
	stroke-opacity: 0.75;
}

.tabs
{
	z-index: 100;
}

.button
{
	z-index: 101;
	position: absolute;
	right: 0;
	top: 50%;
	transform: translatex(50%) translatey(-50%);
	width: 60px;
	height: 60px;
	border: none;
	border-radius: 50%;
	cursor: pointer;
	outline: none;
	
	display: flex;
	justify-content: center;
	align-items: center;
	
	transition: transform 0.2s ease-in-out;
	
	&:hover
	{
		transform: translatex(52%) translatey(-48%);
	}
}

              
            
!

JS

              
                console.clear();

gsap.registerPlugin(MotionPathPlugin);

const App = () => 
{
	const [opened, setOpened] = React.useState(0);
	
	const [inPlace, setInPlace] = React.useState(0);
	const [disabled, setDisabled] = React.useState(false);
	
	const images = [
		{ title: 'Mini canine', url: 'https://images.unsplash.com/photo-1583551536442-0fc55ac443f6?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=600&h=600&fit=min&ixid=eyJhcHBfaWQiOjE0NTg5fQ'},
		{ title: 'Wheely tent', url: 'https://images.unsplash.com/photo-1583797227225-4233106c5a2a?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=600&h=600&fit=min&ixid=eyJhcHBfaWQiOjE0NTg5fQ'},
		{ title: 'Red food things', url: 'https://images.unsplash.com/photo-1561626450-730502dba332?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=600&h=600&fit=min&ixid=eyJhcHBfaWQiOjE0NTg5fQ'},
		{ title: 'Sand boat', url: 'https://images.unsplash.com/photo-1585221454166-ce690e60465f?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=600&h=600&fit=min&ixid=eyJhcHBfaWQiOjE0NTg5fQ'},
		{ title: 'Animal Crossing box', url: 'https://images.unsplash.com/photo-1585427795543-33cf23ea2853?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=600&h=600&fit=min&ixid=eyJhcHBfaWQiOjE0NTg5fQ'},
		{ title: 'Horse tornado', url: 'https://images.unsplash.com/photo-1507160874687-6fe86a78b22e?ixlib?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=600&h=600&fit=min&ixid=eyJhcHBfaWQiOjE0NTg5fQ'},
	]
	
	const onClick = (index) => { if(!disabled) setOpened(index); }
	const onInPlace = (index) => setInPlace(index);
	
	const next = () =>
	{
		let nextIndex = opened + 1;
		if(nextIndex >= images.length) nextIndex = 0;
		onClick(nextIndex);
	}
	
	React.useEffect(() => setDisabled(true), [opened])
	React.useEffect(() => setDisabled(false), [inPlace])
	// React.useEffect(() => {
	// 	if(CodePen && CodePen.isThumbnail)
	// 	{
	// 		setTimeout(() => next(), 100)
	// 	}
	// }, [])
	
	return (
		<React.Fragment>
			<div className="container shadow">
				{ images.map((image, i) => <div key={image.url} className="image" style={{zIndex: inPlace === i ? i : images.length + 1}}><Image total={images.length} id={i} url={image.url} title={image.title} open={opened === i} inPlace={inPlace === i}  onInPlace={onInPlace} /></div>)}
				<div className="tabs"><Tabs className="tabs" images={images}  onSelect={onClick}/></div>
			</div>
			
			<button className="button next shadow" onClick={next}><svg width="24" height="24" viewBox="0 0 24 24"> <path d="M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z" /> </svg></button>	
		</React.Fragment>
	);	
}

const Image = ({url, title, open, inPlace, id, onInPlace, total}) => 
{
	const [firstLoad, loaded] = React.useState(true);
	const clip = React.useRef(null);
	const border = React.useRef(null);
	
	const gap = 10;
	const circle = 7;
	const defaults = { transformOrigin: 'center center' };
	const duration = 0.5;
	const width = 400;
	const height = 400;
	const scale = 700;
	
	let bigSize = (circle * scale);
	let overlap = 0;
	
	const getPosSmall = () => ({x: (width / 2) - ((total * ((circle * 2) + gap) - gap) / 2) + (id * ((circle * 2) + gap)), y: height - 30, scale: 1})
	const getPosSmallAbove = () => ({x: (width / 2) - ((total * ((circle * 2) + gap) - gap) / 2) + (id * ((circle * 2) + gap)), y: height / 2, scale: 1})
	const getPosSmallBelow = () => ({x: width * 0.5, y: height - 30, scale: 1})
	const getPosCenter = () => ({x: width / 2, y: height / 2, scale: 7})
	const getPosEnd = () => ({x: width / 2 - bigSize + overlap, y: height / 2, scale: scale})
	const getPosStart = () => ({x: width / 2 + bigSize - overlap, y: height / 2, scale: scale})

	const onStateChange = () => {
		loaded(false);
		if(border.current)
		{
			gsap.set(border.current, { ...defaults, ...getPosSmall()});
			console.log(border.current)
		}
		if(clip.current)
		{
			let flipDuration = firstLoad ? 0 : duration;
			let upDuration = firstLoad ? 0 : 0.6;
			let bounceDuration = firstLoad ? 0.01 : 1;
			let delay = firstLoad ? 0 : flipDuration + upDuration;
			
			if(open)
			{
				gsap.fromTo(
					`.letters_${id}`, 
					{rotation: 'random(-180, 180)', x: `random(${width * 0.7}, ${width * 0.9})`, y: `random(${height * 0.4}, ${height * 0.6})`, opacity: 1}, 
					{ease: 'power3.Out', delay: `random(${upDuration + 0.2}, ${upDuration + 0.6})`, duration: flipDuration * 1.5, opacity: 1, rotation: 0, motionPath:[{x: width * 0.1, y: height * 0.5}, {x: 40, y: 60}]}
				);
				
				gsap.timeline()
					.set(clip.current, { ...defaults, ...getPosSmall()})
					.to(clip.current, { ...defaults, ...getPosCenter(), duration: upDuration, ease: 'power3.inOut'})
					.to(clip.current, { ...defaults, ...getPosEnd(), duration: flipDuration, ease: 'power4.in', onComplete: () => onInPlace(id)})
			}
			else
			{
				gsap.timeline()
					.fromTo(`.letters_${id}`, {x: 40, y: 60, rotation: 0}, {delay: 0.7, duration: duration * 2, x: `random(${width * 0.24}, ${width - 100})`, y: `random(${20}, ${height/2})`, opacity: 0.75, rotation: 'random(-90, 90)', ease: 'Power3.Out'})
					// .to(`.letters_${id}`, {duration: 0.3, ease: 'power2.in', opacity: 0, x: width / 2, y: height / 2})
				
				gsap.timeline({overwrite: true})
					 .set(clip.current, { ...defaults, ...getPosStart() })
					 .to(clip.current, { ...defaults, ...getPosCenter(), delay: delay, duration: flipDuration, ease: 'power4.out'})
					 .to(clip.current, { ...defaults, motionPath:[getPosSmallAbove(), getPosSmall()], duration: bounceDuration, ease: 'bounce.out'})
			}
		}
	}
	
	React.useEffect(onStateChange, [open, clip])
	
	return (
		<svg xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" viewBox={`0 0 ${width} ${height}`} preserveAspectRatio="xMidYMid slice">
			<defs>
				<clipPath id={id + "_circleClip"}>
					<circle class="clip" cx="0" cy="0" r={circle} ref={clip}></circle>			
				</clipPath>
				<clipPath id={id + "_squareClip"}>
					<rect class="clip" width={width} height={height}></rect>			
				</clipPath>
		  	</defs>
			<g clipPath={`url(#${id + (inPlace ? '_squareClip' : '_circleClip')})`}>
		  		<image width={width} height={height} xlinkHref={url} ></image>
				<g transform="translate(0 0)">
					{ title.split('').map( (letter, i) => <text className={'letters_'+id} x={16 * i} y={0}>{letter}</text> )}
				</g>
			</g>
		</svg>	
	);	
}

const Tabs = ({images, onSelect}) => 
{
	const gap = 10;
	const circle = 7;
	const defaults = { transformOrigin: 'center center' };
	const width = 400;
	const height = 400;
	
	const getPosX = (i) => (width / 2) - ((images.length * ((circle * 2) + gap) - gap) / 2) + (i * ((circle * 2) + gap))
	const getPosY = (i) => height - 30
	
	return (
		<svg xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" viewBox={`0 0 ${width} ${height}`} preserveAspectRatio="xMidYMid slice">
		  	{ (!images ? [] : images).map((image, i) => <circle onClick={() => onSelect(i)} className="border" cx={getPosX(i)} cy={getPosY(i)} r={circle + 2}></circle> )}
		</svg>
	);	
}

ReactDOM.render(<App />, document.getElementById('app'));
              
            
!
999px

Console