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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

            
              <section>
	<div class="image is-center">
		<div class="image__top"></div>
		<div class="image__stretch">
			<div class="image__inner"></div>
		</div>
		<div class="image__bottom"></div>
	</div>
	<div class="text">
		<span class="text__word" id="word">使徒、襲来</span>
		<p class="text__subtitle"> Angel Attack </p>
	</div>
</section>
<section>
	<div class="image">
		<div class="image__top"></div>
		<div class="image__stretch">
			<div class="image__inner"></div>
		</div>
		<div class="image__bottom"></div>
	</div>
	<div class="text">
		<span class="text__word" id="word">嘘と沈黙</span>
		<p class="text__subtitle"> Lies and Silence </p>
	</div>
</section>
<section>
	<div class="image">
		<div class="image__top"></div>
		<div class="image__stretch">
			<div class="image__inner"></div>
		</div>
		<div class="image__bottom"></div>
	</div>
	<div class="text">
		<span class="text__word" id="word">人の造り</span>
		<p class="text__subtitle"> A Human Work </p>
	</div>
</section>
<section>
	<div class="image">
		<div class="image__top"></div>
		<div class="image__stretch">
			<div class="image__inner"></div>
		</div>
		<div class="image__bottom"></div>
	</div>
	<div class="text">
		<span class="text__word" id="word">魂の座</span>
		<p class="text__subtitle"> Throne of Souls </p>
	</div>
</section>
<section>
	<div class="image">
		<div class="image__top"></div>
		<div class="image__stretch">
			<div class="image__inner"></div>
		</div>
		<div class="image__bottom"></div>
	</div>
	<div class="text">
		<span class="text__word" id="word">奇跡の価値</span>
		<p class="text__subtitle"> The Value of Miracles </p>
	</div>
</section>
<section>
	<div class="image">
		<div class="image__top"></div>
		<div class="image__stretch">
			<div class="image__inner"></div>
		</div>
		<div class="image__bottom"></div>
	</div>
	<div class="text">
		<span class="text__word" id="word">使徒、侵入</span>
		<p class="text__subtitle"> Angel Invasion </p>
	</div>
</section>

<div class="stripe" id="stripe">
	<button class="prev" id="prev">-</button>
	<button class="next" id="next">+</button>
	
</div>


            
          
!
            
              $w: 80vmin;
$h: 60vmin;
$p: 0.5;
$s: 0.2;

$font: 'Space Mono', monospace;

$ease: cubic-bezier(0.770, 0.000, 0.175, 1.000);

html{
	background-color: #111;
	padding: 20vh 0;
}

.stripe{
	position: fixed;
	top: 37.5vh;
	left: 0vw;
	width: 100vw;
	height: 25vh;
	background: tomato;
	z-index: 0;
	mix-blend-mode: darken;
	pointer-events: none;
	.next, .prev{
		pointer-events: auto;
		appearance: none;
		font-family: $font;
		background: transparent;
		color: white;
		outline: none;
		position: absolute;
		top: 50%;
		left: calc(50vw - 47vmin);
		cursor: pointer;
		height: 4vmin;
		width: 4vmin;
		font-size: 2vmin;
		border: none;
		box-sizing: border-box;
	}
	.next{
		transform: translateY(50%);
		border-top: none;
	}
	.prev{
		transform: translateY(-140%);

	}
}

section{
	position: relative;
	height: 60vh;
	&:nth-child(1){
		.image__top, .image__bottom, .image__inner{
			background-image: url('https://picsum.photos/801/601?image=321');
		}
	}
	&:nth-child(2){
		.image__top, .image__bottom, .image__inner{
			background-image: url('https://picsum.photos/802/602?image=208');
		}
	}
	&:nth-child(3){
		.image__top, .image__bottom, .image__inner{
			background-image: url('https://picsum.photos/803/603?image=608');
		}
	}
	&:nth-child(4){
		.image__top, .image__bottom, .image__inner{
			background-image: url('https://picsum.photos/803/603?image=565');
		}
	}
	&:nth-child(5){
		.image__top, .image__bottom, .image__inner{
			background-image: url('https://picsum.photos/804/604?image=218');
		}
	}
	&:nth-child(6){
		.image__top, .image__bottom, .image__inner{
			background-image: url('https://picsum.photos/805/605?image=1032');
		}
	}
}

.image{
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate3d(-50%, -50%, 0);
	width: $w;
	height: $h;
	transition: transform 1000ms $ease;
	
	&__top, &__bottom, &__inner{
		width: 100%;
		background-size: $w $h;
	}
	&__top, &__bottom, &__stretch{
		//transition: transform 200ms linear;
	}
	
	&__top{
		height: $p*100%;
		background-position: top;
	}
	
	&__bottom{
		height: (1-$p)*100%;
		background-position: 0% 99%;
	}
	
	&__stretch{
		height: $s*100%;
		overflow: hidden;
		position: relative;
		z-index: 2;
		margin: -1px 0;
	}
	&__inner{
		position: absolute;
		width: 100%;
		height: 100%;
		background-position: 0 $p*100%;
		height: 1px;
		transform: scaleY(1000);
	}
}



.text{
	position: absolute;
	text-align: center;
	top: 50%;
	left: 50%;
	z-index: 100;
	transform: translate3d(-50%,-50%,0);
	z-index: 2;
	font-family: $font;
	text-transform: uppercase;
	font-size: 0;
	color: white;
	cursor: default;
	user-select: none;
	font-weight: 700;
	pointer-events: none;
	
	line-height: 0.9;
	padding-top: 5vh;
	&__word{
		display: block;
		font-size: 10vmin;
		-webkit-text-fill-color: transparent;
		-webkit-text-stroke: 2px white;
	}
	&__subtitle{
		margin-top: 3vh;
		font-size: 2vmin;
		letter-spacing: 0.1em;
		font-weight: 200;
	}
}
            
          
!
            
              //Config
var lag = 12;
var grow = 20;
var shrink = 20;

//Vars
var windowHeight = window.innerHeight;
var scrollAmount = 0;
var stretchAmount = 0;
var stretchDirection = 0;
var mouseDown = false;
var scrollMove = 0;
var transitionProgress = 0;
var currentPrev = null;
var currentNext = null;

//Els
var images = document.getElementsByClassName("image");
var stripe = document.getElementById('stripe');

//Handlers
window.addEventListener('resize', function(){
	windowHeight = window.innerHeight;
})
window.addEventListener('mousedown', function(){
	mouseDown = true;
})
window.addEventListener('mouseup', function(){
	mouseDown = false;
})
for (i = 0, lim = images.length ; i < lim; i++ ){
	images[i].addEventListener('click', function(){
		scrollToImage(this);
	})
}
document.getElementById('prev').addEventListener('click', goToPrev);
document.getElementById('next').addEventListener('click', goToNext);

function scrollToImage(image){
	var bound = image.getBoundingClientRect();
	scrollMove = windowHeight/2 - (bound.top + bound.height/2);
}

function goToPrev(){
	if (currentPrev){
		scrollToImage(currentPrev)
	}
}
function goToNext(){
	if (currentNext){
		scrollToImage(currentNext)
	}
}

//Animate
function animate(){
	
	//UPDATE VARS
	scrollAmount += (window.pageYOffset - scrollAmount)/lag;
	stretchDirection += (window.pageYOffset - scrollAmount)*grow;
	stretchDirection /= shrink;
	
	if (stretchDirection < 0){
		stretchDirection = Math.max( -0.3 * windowHeight, stretchDirection);
	} else {
		stretchDirection = Math.min( 0.3 * windowHeight, stretchDirection);
	}
	stretchAmount = Math.abs(stretchDirection);
	
	//SCROLL POSITION
	if (Math.floor(Math.abs(scrollMove)) !== 0){
		var thisMove = Math.floor(scrollMove / lag);
		window.scrollTo(0, window.pageYOffset - thisMove);
		scrollMove -= thisMove;
	}
	
	//TRANSITION
	if (mouseDown){
		transitionProgress += 0.01;
		transitionProgress *= 1 + transitionProgress/grow;
	} else {
		transitionProgress *= 1 - transitionProgress/shrink;
	}
	transitionProgress = Math.min(transitionProgress, 1);
	
	//POSITION ELEMENTS
	
	//Images
	for (i = 0, lim = images.length ; i < lim; i++ ){
		var image = images[i];
		var bound = image.getBoundingClientRect();
		var progress = ( windowHeight - bound.top ) / ( windowHeight + bound.height );
		
		progress = Math.max(0, Math.min(1, progress));
			
		if (bound.top > 0 && bound.bottom < windowHeight){
			addClass(image, 'is-center');
			currentPrev = images[i-1] || image;
			currentNext = images[i+1] || image;
		} else {
			removeClass(image, 'is-center');
		}
		
		var top = image.children[0];
		var stretch = image.children[1];
		var stretchInner = stretch.children[0];
		var bottom = image.children[2];
		
		// Top
		top.style.height = progress * 100 + "%";	
		top.style.transform = 'translateY(' + ( stretchDirection + (0.5 - progress) * windowHeight) + 'px)';

		// Stretch 
 		stretch.style.height = stretchAmount + 2 + "px";
		stretch.style.transform = 'translateY(' + ( stretchDirection + (0.5 - progress) * windowHeight) + 'px)';
 		stretchInner.style.backgroundPosition = "0 " + progress * 100 + "%";
		
 		// Bottom
 		bottom.style.height = (1 - progress) * 100 + "%";
		bottom.style.transform = 'translateY(' + ( stretchDirection + (0.5 - progress) * windowHeight) + 'px)';

	}
	
	// Stripe
	//stripe.style.transform = 'scaleY(' + (1+transitionProgress*3) + ')';

	
	requestAnimationFrame(animate)
}

requestAnimationFrame(animate)


//utility
function addClass(el, className) {
    if (el.classList) el.classList.add(className);
    else if (!hasClass(el, className)) el.className += ' ' + className;
}

function removeClass(el, className) {
    if (el.classList) el.classList.remove(className);
    else el.className = el.className.replace(new RegExp('\\b'+ className+'\\b', 'g'), '');
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console