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

Auto Save

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

              
                <main class="vs-section">
  <div id="section1" class="panel"><h1>test</h1></div>
  <div id="section2" class="panel"><h1 id="animate-this">test animate</h1></div>
  <div id="section3" class="panel"><h1>test</h1></div>
  <div id="section4" class="panel"><h1>test</h1></div>
</main>
              
            
!

CSS

              
                
html {
  color: white;
  font-size: 1em;
  line-height: 1.4;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
}
body {
  font-family: system-ui, sans-serif;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  background-color: blue;
  overflow: hidden;
  position: fixed;
  left: 0;
  top: 0;
  margin: 0;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none; 
  -ms-overflow-style: none; /* for Internet Explorer, Edge */
  /* scrollbar-width: none;  */
  /* overflow-y: scroll;    */
}

body::-webkit-scrollbar {
  display: none; /* for Chrome, Safari, and Opera */
}

h1 {
  color: white;
}
main {
  display: grid;
  /* background-color: black; */
  grid-template-rows: repeat(4, 1fr);
}
#section1 {
  height: 100vh;
  width: 100vw;
  display: grid;
  background-color: black;
}
#section2 {
  background: red;
}
#section3 {
  background: green;
}
#section4 {
  background: blue;
}
.panel {
  height: 100vh;
  width: 100vw;
  position: relative;
}

.vs-section {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height:100%;
  will-change: transform;
}
   
              
            
!

JS

              
                var VirtualScroll = (function(document) {

	var vs = {};

	var numListeners, listeners = [], initialized = false;

	var touchStartX, touchStartY;

	// [ These settings can be customized with the options() function below ]
	// Mutiply the touch action by two making the scroll a bit faster than finger movement
	var touchMult = 2;
	// Firefox on Windows needs a boost, since scrolling is very slow
	var firefoxMult = 15;
	// How many pixels to move with each key press
	var keyStep = 120;
	// General multiplier for all mousehweel including FF
	var mouseMult = 1;

	var bodyTouchAction;

	var hasWheelEvent = 'onwheel' in document;
	var hasMouseWheelEvent = 'onmousewheel' in document;
	var hasTouch = 'ontouchstart' in document;
	var hasTouchWin = navigator.msMaxTouchPoints && navigator.msMaxTouchPoints > 1;
	var hasPointer = !!window.navigator.msPointerEnabled;
	var hasKeyDown = 'onkeydown' in document;

	var isFirefox = navigator.userAgent.indexOf('Firefox') > -1;

	var event = {
		y: 0,
		x: 0,
		deltaX: 0,
		deltaY: 0,
		originalEvent: null
	};

	vs.on = function(f) {
		if(!initialized) initListeners(); 
		listeners.push(f);
		numListeners = listeners.length;
	}

	vs.options = function(opt) {
		keyStep = opt.keyStep || 120;
		firefoxMult = opt.firefoxMult || 15;
		touchMult = opt.touchMult || 2;
		mouseMult = opt.mouseMult || 1;
	}

	vs.off = function(f) {
		listeners.splice(f, 1);
		numListeners = listeners.length;
		if(numListeners <= 0) destroyListeners();
	}

	var notify = function(e) {
		event.x += event.deltaX;
		event.y += event.deltaY;
		event.originalEvent = e;

		for(var i = 0; i < numListeners; i++) {
			listeners[i](event);
		}
	}

	var onWheel = function(e) {
		// In Chrome and in Firefox (at least the new one)
		event.deltaX = e.wheelDeltaX || e.deltaX * -1;
		event.deltaY = e.wheelDeltaY || e.deltaY * -1;

		// for our purpose deltamode = 1 means user is on a wheel mouse, not touch pad 
		// real meaning: https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent#Delta_modes
		if(isFirefox && e.deltaMode == 1) {
			event.deltaX *= firefoxMult;
			event.deltaY *= firefoxMult;
		} 

		event.deltaX *= mouseMult;
		event.deltaY *= mouseMult;

		notify(e);
	}

	var onMouseWheel = function(e) {
		// In Safari, IE and in Chrome if 'wheel' isn't defined
		event.deltaX = (e.wheelDeltaX) ? e.wheelDeltaX : 0;
		event.deltaY = (e.wheelDeltaY) ? e.wheelDeltaY : e.wheelDelta;

		notify(e);	
	}

	var onTouchStart = function(e) {
		var t = (e.targetTouches) ? e.targetTouches[0] : e;
		touchStartX = t.pageX;	
		touchStartY = t.pageY;
	}

	var onTouchMove = function(e) {
		// e.preventDefault(); // < This needs to be managed externally
		var t = (e.targetTouches) ? e.targetTouches[0] : e;

		event.deltaX = (t.pageX - touchStartX) * touchMult;
		event.deltaY = (t.pageY - touchStartY) * touchMult;
		
		touchStartX = t.pageX;
		touchStartY = t.pageY;

		notify(e);
	}

	var onKeyDown = function(e) {
		// 37 left arrow, 38 up arrow, 39 right arrow, 40 down arrow
		event.deltaX = event.deltaY = 0;
		switch(e.keyCode) {
			case 37:
				event.deltaX = -keyStep;
				break;
			case 39:
				event.deltaX = keyStep;
				break;
			case 38:
				event.deltaY = keyStep;
				break;
			case 40:
				event.deltaY = -keyStep;
				break;
		}

		notify(e);
	}

	var initListeners = function() {
		if(hasWheelEvent) document.addEventListener("wheel", onWheel);
		if(hasMouseWheelEvent) document.addEventListener("mousewheel", onMouseWheel);

		if(hasTouch) {
			document.addEventListener("touchstart", onTouchStart);
			document.addEventListener("touchmove", onTouchMove);
		}
		
		if(hasPointer && hasTouchWin) {
			bodyTouchAction = document.body.style.msTouchAction;
			document.body.style.msTouchAction = "none";
			document.addEventListener("MSPointerDown", onTouchStart, true);
			document.addEventListener("MSPointerMove", onTouchMove, true);
		}

		if(hasKeyDown) document.addEventListener("keydown", onKeyDown);

		initialized = true;
	}

	var destroyListeners = function() {
		if(hasWheelEvent) document.removeEventListener("wheel", onWheel);
		if(hasMouseWheelEvent) document.removeEventListener("mousewheel", onMouseWheel);

		if(hasTouch) {
			document.removeEventListener("touchstart", onTouchStart);
			document.removeEventListener("touchmove", onTouchMove);
		}
		
		if(hasPointer && hasTouchWin) {
			document.body.style.msTouchAction = bodyTouchAction;
			document.removeEventListener("MSPointerDown", onTouchStart, true);
			document.removeEventListener("MSPointerMove", onTouchMove, true);
		}

		if(hasKeyDown) document.removeEventListener("keydown", onKeyDown);

		initialized = false;
	}

	return vs;
})(document);




/////////////// ^ added http://www.everyday3d.com/blog/index.php/2014/08/18/smooth-scrolling-with-virtualscroll/ //////////
/////////////////////////////////////////////////////////



let section = document.querySelector('.vs-section'),
	sectionHeight = section.getBoundingClientRect().height,
	scrollHeightClient = section.clientHeight,
	targetY = 0, 
	currentY = 0, 
	ease = 0.1;

window.addEventListener('resize', this.onResize.bind(this)); 
function onResize() {
	let calcOrient = function calcOrientation() {
	  const mediaQueryList = window.matchMedia("(orientation: portrait)");
		function handleOrientationChange(mql) {
			panel = document.querySelector('.panel').clientHeight;
					heightScroll = scrollHeightClient;
		}
		handleOrientationChange(mediaQueryList);
		mediaQueryList.addEventListener('change', handleOrientationChange);
	}();
		return [heightScroll, panel];
}
 
	VirtualScroll.on(function(e) {
			let varDimensiuniEcran = onResize();
			const heightScroll = varDimensiuniEcran[0],
				    panel = varDimensiuniEcran[1];
			targetY += e.deltaY;
			targetY = Math.round(Math.max( ( heightScroll * +3) /                   scrollHeightClient * - panel, targetY));
			targetY = Math.min(0, targetY);
		});	

		runScrollz = function() {
			requestAnimationFrame(runScrollz);
			currentY += (targetY - currentY) * ease;
			let t = 'translateY(' + currentY.toFixed(3) + 'px) translateZ(0)';
			let s = section.style;
			s["transform"] = t;
			s["webkitTransform"] = t;
			s["mozTransform"] = t;
			s["msTransform"] = t;
		};

runScrollz();


//// setup scrolltrigger ??? 

// need to add this https://greensock.com/docs/v3/Plugins/ScrollTrigger/static.scrollerProxy()

gsap.registerPlugin(ScrollTrigger);

gsap.to("#animate-this", {
		scrollTrigger: {
		trigger: "#section1",
		start: "0%",
		end: "90%",	
		id: "left",
		scroller: ".vs-section",
		scrub: 1,
		markers: false,
		toggleActions: "play none none reverse"
		}, 
		duration: 1,
		xPercent:"-50",
		rotation: "-17_short",
		transformOrigin: "left bottom",
		ease:'power1.out'
	});	
              
            
!
999px

Console