Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                <ul class="vampires">

	<li class="vampire">
		<span>Blade <cite>The Blade Trilogy</cite></span>
		<img src="https://assets.codepen.io/4325932/vampire-blade.png" alt="A portrait of Blade"/>
	</li>
	<li class="vampire">
        <span>Count Dracula <cite><q>Dracula</q>, by Bram Stoker</cite></span>
        <img src="https://assets.codepen.io/4325932/vampire-count-dracula.png" alt="A portrait of Count Dracula"/>
	</li>
	<li class="vampire">
        <span>Count von Count <cite>Sesame Street</cite></span>
        <img src="https://assets.codepen.io/4325932/vampire-count-von-count.png" alt="A portrait of Count von Count"/>
	</li>
	<li class="vampire">
        <span>Edward Cullen <cite>The Twilight Saga</cite></span>
        <img src="https://assets.codepen.io/4325932/vampire-edward-cullen.png" alt="A portrait of Edward Cullen"/>
	</li>
	<li class="vampire">
        <span>Grandpa Munster <cite>The Munsters</cite></span>
        <img src="https://assets.codepen.io/4325932/vampire-grandpa-monster.png" alt="A portrait of Grandpa Munster"/>
	</li>
	<li class="vampire">
        <span>Lazlo Cravensworth <cite>What We Do in the Shadows</cite></span>
        <img src="https://assets.codepen.io/4325932/vampire-lazlo-cravensworth.png" alt="A portrait of Lazlo Cravensworth"/>
	</li>
	<li class="vampire">
        <span>Larten Crepsley <cite>Cirque du Freak: The Vampire's Assistant</cite></span>
        <img src="https://assets.codepen.io/4325932/vampire-larten-crepsley.png" alt="A portrait of Larten Crepsley"/>
	</li>
	<li class="vampire">
        <span>Lestat de Lioncourt <cite>The Vampire Chronicles</cite></span>
        <img src="https://assets.codepen.io/4325932/vampire-lestat-de-lioncourt.png" alt="A portrait of Lestat de Lioncourt"/>
	</li>
	<li class="vampire">
        <span>Selene <cite>Underworld</cite></span>
        <img src="https://assets.codepen.io/4325932/vampire-selene.png" alt="A portrait of Selene"/>
	</li>
	<li class="vampire">
        <span>Spike <cite>Buffy the Vampire Slayer</cite></span>
        <img src="https://assets.codepen.io/4325932/vampire-spike.png" alt="A portrait of Spike"/>
	</li>
</ul>

<div class="peanut" aria-hidden="true">
  <div class="peanut-inner"></div>   
</div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Kanit:[email protected];700&display=swap');

*{
	margin: 0;
	padding: 0;
	box-sizing: border-box;
	list-style-type: none;
	font-style: unset;
}

body{
	--color-01: #ededed;
	--color-02: #FFD700;
  
	background: #191919;
	font-family: 'Kanit', sans-serif;
	font-weight: 200;
  
	.vampires{
		position:relative;
		margin: 50px auto;
		width: calc(100vw - 40px);
		max-width: 1000px;

		.vampire{
			padding: 0 20px;
			padding: 20px 0;
			font-size: clamp(22px, 7.5vmin, 100px);
			text-transform: uppercase;
			color: transparent;
			-webkit-text-stroke: 1px var(--color-01, white);
			font-weight: 700;
			transition: color .2s ease;
			position: relative;
			cursor: pointer;

			&::selection {
				background: var(--color-02, yellow);
			}

			cite{
				display: block;
				position: absolute;
				bottom: 10px;
				opacity: 0;
				font-size: clamp(1rem, 2vmin, 1.5rem);
				text-transform: none;
				-webkit-text-stroke: unset;
				color: var(--color-01, white);
				font-weight: initial;
				transition: opacity .2s ease, bottom .2s ease;
			}

			img{
				display: none;
			}

			&:hover{
				color: var(--color-01, white);

				cite{
					opacity: 1;
					bottom: 5px;
				}
			}
		}
	}

	.peanut{
		width: 20vw;
		min-width: 70px;
		max-width: 200px;
		aspect-ratio: 0.75;
		position: fixed;
		z-index: -1;
		top: var(--top, 50vh);
		left: var(--left, 50vw);
		transform: translate(-50%, -50%);
		display: grid;
		opacity: 0;
		transition: top .2s ease-out,
			left .2s ease-out,
			opacity .2s ease;

		.peanut-inner{
			background-color: black;
			transform: rotate(var(--rotation, 0deg));
			transition: transform .15s ease-out;
			background-repeat: no-repeat;
			background-position: center;
			background-size: cover;
			background-image: var(--cover-1);
			display: grid;
			overflow: hidden;

			&:before{
				content:'';
				transform: translateX(100%);
				background-repeat: no-repeat;
				background-position: center;
				background-size: cover;
				background-image: var(--cover-2);
				transition: transform 0s ease;
			}

			&.appear{
				&:before{
					transform: translateX(0%);
					transition: transform .2s ease;
				}
			}
		}
	}

	.vampires:hover ~ .peanut{
		opacity: 1;    
	}
}
              
            
!

JS

              
                const peanut = document.querySelector('.peanut');
const peanut_inner = peanut.querySelector('.peanut-inner');
const list = document.querySelector('.vampires');
const vampires = list.querySelectorAll('.vampire');
let rotation;

peanut_inner.classList.add('appear');

list.addEventListener('mousemove', (e) => {
  clearTimeout(rotation);
  
  const top = e.clientY / window.innerHeight * 100;
  const left = e.clientX / window.innerWidth * 100;
  const currentX = peanut.getBoundingClientRect().left + peanut.getBoundingClientRect().width / 2;
  const rotate = (left - (currentX / window.innerWidth * 100)) * 0.5;
  
  peanut.style.setProperty("--top", `${top}%`);
  peanut.style.setProperty("--left", `${left}%`);
  peanut.style.setProperty("--rotation", `${rotate}deg`);
  
  rotation = setTimeout(() => {
    peanut.style.setProperty("--rotation", `$0deg`);
  }, 100)
})

vampires.forEach(vampire => {
  vampire.addEventListener('mouseenter', () => {
    const cover = vampire.querySelector('img').src;
    
    peanut_inner.style.setProperty("--cover-2", `url('${cover}')`);
    peanut_inner.classList.add('appear');
    
     setTimeout(() => {
       peanut_inner.style.setProperty("--cover-1", `url('${cover}')`);
       peanut_inner.classList.remove('appear');
     }, 200)
  });
});

list.addEventListener('mouseleave', () => {
  setTimeout(() => {
    peanut_inner.style.setProperty("--cover-1", '');
    peanut_inner.style.setProperty("--cover-2", '');
    peanut_inner.classList.add('appear');
  }, 200)
});
              
            
!
999px

Console