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 class="stage">
    <div class="tube">
        <div class="tube__inner">
            <h1 class="line">滚筒中文测试</h1>
        </div>
	</div>
</div>
              
            
!

CSS

              
                @font-face {
    /* 
	Bandeins Strange 
	http://type.bandeins.de/
	This free font is for demonstration purposes only. You may not distribute, rent, sell, give away, publicly or privately share any modified or unmodified version of the font. Special permission has been granted to crosslink to it for demo purposes only. You must obtain an appropriate license at <http://type.bandeins.de/> before linking to this font or using it in any other context.
	*/
    font-family: 'Bandeins-Strange';
    src: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/61488/BandeinsStrangeVariableGX.ttf') format('truetype');
    font-stretch: 100% 800%;
    font-weight: 200 800;
    font-display: block;
}

:root {
    --fontSize: 4;
}

html {
	box-sizing: border-box;
}

*, *:before, *:after {
	box-sizing: inherit;
}

html, body {
	width: 100%;
	height: 100%;
}

body {
    color: white;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    height: 1000vh;
    background: black;
}

.stage {
    display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
    height: 100%;
    visibility: hidden;
}

.tube {
    position: fixed;
    top: 50vh;
    left: 0vw;
    perspective: 100vw;
    width: 100vw;
}

.tube__inner {
    position: relative;
    transform-style: preserve-3d;
}

.line {
    position: absolute;
    top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
    margin: 0;
    font-family: 'Bandeins-Strange';
    font-size: calc(var(--fontSize) * 1vw);
    font-stretch: 800%;
    font-weight: 800;
    text-transform: uppercase;
    line-height: 1;
    transform-style: preserve-3d;
    color: yellow;
}
              
            
!

JS

              
                console.clear();

select = e => document.querySelector(e);
selectAll = e => document.querySelectorAll(e);

const stage = select('.stage');
const tubeInner = select(".tube__inner");
const clone = document.getElementsByClassName("line"); // as need to update node list
const numLines = 10;
const fontSize = gsap.getProperty(':root', '--fontSize');
const angle = 360/numLines;
let radius = 0;
let origin = 0;

function set3D() {
    let width = window.innerWidth;
    let fontSizePx = (width/100)*fontSize;
    radius = (fontSizePx/2)/Math.sin((180/numLines)*(Math.PI/180)); // using Pythagoras Eq
    origin = `50% 50% -${radius}px`;
}

function clodeNode() {
    
    for (var i = 0; i < (numLines-1); i++) {
        let newClone = clone[0].cloneNode(true); // clone the header
        let lineClass = "line--"+(i+2); // create class name to append
        newClone.classList.add(lineClass); // add incremented line class
        tubeInner.appendChild(newClone); // append the clone
    }
    
    clone[0].classList.add("line--1"); // add line1 class to the first node
}

function positionTxt() {
	gsap.set('.line', {
		rotationX: function(index) {
			return -angle*index;
		},
		z: radius,
		transformOrigin: origin
	});
}

function setProps(targets) {
    targets.forEach( function(target) {
        let paramSet = gsap.quickSetter(target, "css");
        let degrees = gsap.getProperty(target, "rotateX");
        let radians = degrees * (Math.PI/180);
        let conversion = Math.abs(Math.cos(radians) / 2 + 0.5); // 1 - 0 half cosine wave
        let fontW = 200 + 700*conversion;
        let fontS = `${100 + 700*conversion}%`;

        paramSet({
            opacity: conversion+0.1, 
            // x: 300*conversion, 
            fontWeight: fontW, 
            fontStretch: fontS 
        });
        console.log(fontW);
    })
}

function scrollRotate() {
    gsap.to('.line', {
        scrollTrigger: {
            trigger: '.stage',
            scrub: 1,
            start: "top top",
            // markers: {
            //     startColor: "white", 
            //     endColor: "red", 
            //     fontSize: "16px", 
            //     fontWeight: "bold", 
            //     indent: 0
            // }
        },
        rotateX: "+=1080",
        onUpdate: function() {
            setProps(this.targets());
        }
    })
    
    gsap.to('.tube', {
        scrollTrigger: {
            trigger: '.stage',
            scrub: 1,
            start: "top top"
        },
        perspective: '1vw',
        ease: 'expo.out'
    })
}

function init() {
    clodeNode();
    set3D();
    window.onresize = () => {
        set3D();
        positionTxt();
    }
    positionTxt(); 
    setProps(gsap.utils.toArray(".line"));
    scrollRotate();
    gsap.to(stage, { autoAlpha: 1, duration: 2, delay: 2 });
}

window.onload = () => {
	init();
};
              
            
!
999px

Console