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

              
                <div class="page">

<div class="container">
	
	<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 520 520" class="results__dial">
		<title>Calculator Savings Dial</title>
		<g class="results__dial-circles">
			<g transform="rotate(-90 260 264)">
				<circle class="results__dial-outer" cx="260" cy="264" r="200" fill="none" stroke="#64d3de" stroke-miterlimit="10" opacity="0.6" />
			</g>
			<g transform="rotate(-90 260 264)">
				<circle class="results__dial-track" cx="260" cy="264" r="178" fill="none" stroke="#50afb8" stroke-miterlimit="10" stroke-width="8" />
			</g>
			<g transform="rotate(-90 260 264)">
				<circle class="results__dial-track-perc" cx="260" cy="264" r="178" fill="none" stroke="#fff" stroke-miterlimit="10" stroke-width="8"/>
			</g>
		</g>
		<g class="results__dial-markers" fill="#64d3de">
			<rect class="results__dial-marker" x="260" y="55" width="1" height="9" />
			<rect class="results__dial-marker" x="260" y="55" width="1" height="9" />
			<rect class="results__dial-marker" x="260" y="55" width="1" height="9" />
			<rect class="results__dial-marker" x="260" y="55" width="1" height="9" />
			<rect class="results__dial-marker" x="260" y="55" width="1" height="9" />
			<rect class="results__dial-marker" x="260" y="55" width="1" height="9" />
		</g>
		<g class="results__dial-percent-text" fill="#64d3de" font-size="18" >
			<text x="255" y="43.99">0%</text>
			<text x="388" y="86.99">10%</text>
			<text x="471" y="199.99">20%</text>
			<text x="470" y="340.99">30%</text>
			<text x="381" y="454.99">40%</text>
			<text x="250" y="495.99">50%</text>
		</g>
		<g class="">
			<text class="results__dial-perc-text results__text" x="272" y="203.98" fill="#fff">
				<tspan class="results__dial-perc" text-anchor="start">0</tspan>
				<tspan baseline-shift="super">%</tspan>
			</text>
			<text class="results__dial-effect results__text" x="154.43" y="236.67" font-size="16" fill="#64d3de">INCREASE IN HAND HYGIENE
				<tspan x="175" dy="24">EFFECTIVENESS SAVES:</tspan>
			</text>
			<text class="results__dial-results results__text" text-anchor="middle" x="250" y="318" fill="#64d3de">
				<tspan baseline-shift="super">$</tspan>
				<tspan fill="#fff" class="results__dial-saving">0</tspan>
			</text>
		</g>
		<g class="results__dial-drag" fill="#fff">
			<g class="results__dial-drag-inner">
				<circle class="results__dial-drag-hit" cx="260" cy="35" r="30" fill="white" opacity="0" />
				<circle class="results__dial-drag-pad" cx="260" cy="35" r="20" />
				<g class="results__dial-drag-arrows" fill="#092a30">
					<polygon points="266.73 38.66 266 37.96 268.55 35.48 266 33.01 266.73 32.3 270 35.48 266.73 38.66" />
					<polygon points="253.27 38.66 254 37.96 251.45 35.48 254 33.01 253.27 32.3 250 35.48 253.27 38.66" />
					<rect x="251" y="35" width="18" height="1"  />
				</g>
			</g>
			<rect class="results__dial-drag-line" x="260" y="55" width="1" height="35" />
		</g>
	</svg>


</div>

</div>
              
            
!

CSS

              
                /*  ==========================================================================
    Variables etc
    ========================================================================== */

%thin {
	font-family: "proxima-nova",sans-serif;
	font-style: normal;
	font-weight: 100;
}

%light {
	font-family: "proxima-nova",sans-serif;
	font-style: normal;
	font-weight: 300;
}

%normal {
	font-family: "proxima-nova",sans-serif;
	font-style: normal;
	font-weight: 400;
}

%bold {
	font-family: "proxima-nova",sans-serif;
	font-style: normal;
	font-weight: 700;
}

/*  ==========================================================================
    General
    ========================================================================== */

body {
	// background: rgb(9,42,48);
	background-image: linear-gradient( 340deg, rgb(0,137,150) 0%, rgb(9,42,48) 100%);
	@extend %normal;
	font-feature-settings: "kern" 1, "liga" 1, 'lnum' 1;
	line-height: 1.5;
	-webkit-font-smoothing: antialiased;
}

body,
html {
	height: 100%;
	width: 100%;
	margin: 0;
	padding: 0;
}

.page {
	height: 200vh;
}

.container {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: 520px;
	height: 520px;
}

/*  ==========================================================================
    Dial
    ========================================================================== */

.results__dial {
	visibility: hidden;
	text, tspan {
		user-select: none;
	}
}

/*  Percentage Markers
    ========================================================================== */

.results__dial-percent-text {
	text {
		@extend %normal;
		-webkit-font-smoothing: subpixel-antialiased; // make slightly bolder
	}
}

/*  Text
    ========================================================================== */

// dynamic <text> numbers wrappers
.results__dial-perc-text, .results__dial-results {
	font-feature-settings: "tnum" 1; 
	text-anchor: middle;
}

// percentage <text> wrapper
.results__dial-perc-text, .results__dial-results { 
	font-size: 24px;
	@extend %bold;
}

// percentage value <tspan>
.results__dial-perc {
	@extend %bold;
	text-anchor: middle;
	font-size: 48px;
	-webkit-font-smoothing: subpixel-antialiased; // make slightly bolder
}

// savings value <tspan>
.results__dial-saving {
	@extend %bold;
	font-size: 48px;
	-webkit-font-smoothing: subpixel-antialiased; // make slightly bolder
}

/*  Dragger
    ========================================================================== */

.results__dial-drag-arrows, .results__dial-drag-pad {
	pointer-events: none;
}

.results__dial-drag-hit {
	cursor: pointer;
}
              
            
!

JS

              
                /*  ==========================================================================
    Dial
    ========================================================================== */

var tCost = 8501373;
var hhCost = tCost * 0.5;;
var decreaseScale = 0.006; // per 1%
var savings;
var maxRotation = 179.6;
var rotationSnap = 360/100; // snap to 1% increments
var initEasing = Power4.easeInOut;
var $circOuter = $('.results__dial-outer');
var $circTrack = $('.results__dial-track');
var $trackPerc = $('.results__dial-track-perc');
var $dialMarkers = $('.results__dial-marker');
var $dialMarkerNums = $('.results__dial-percent-text text');
var $drag = $('.results__dial-drag');
var $dragPad = $('.results__dial-drag-pad');
var $dragPadHit = $('.results__dial-drag-hit');
var $dragLine = $('.results__dial-drag-line');
var $dragInner = $('.results__dial-drag-inner');
// var $precText = $('.results__dial-perc-text');
var $resultsText = $('.results__text');
var $perc = $('.results__dial-perc');
// var $effectText = $('.results__dial-effect');
// var $savingText = $('.results__dial-results');
var $saving = $('.results__dial-saving');
var dialTL = new TimelineMax();

TweenMax.set('.results__dial', {
	visibility: 'visible'
});

TweenMax.set([$trackPerc,$circOuter,$circTrack], {
		transformOrigin: '50% 50%',
		drawSVG: '0% 0%'
	});

TweenMax.set($drag, {
		transformOrigin:"50% 259", // set rotationY to the center of the dial
		rotation: 0
	})

TweenMax.set($dialMarkers, {
		transformOrigin:"50% 209" // set rotationY to the center of the dial
		// rotation: 0
	})

$dragPadHit.hover(
	function() {
		TweenMax.to($dragPad, 0.4, {
			transformOrigin:"center center",
			scale: 1.2,
			ease: Elastic.easeOut.config(0.9, 0.3)
		});
	}, function() {
		TweenMax.to($dragPad, 0.2, {
			scale: 1
		});
	}
);


dialTL.to($circTrack, 0.8, {
		drawSVG: '0% 100%',
		ease: initEasing
	})

	.to($circOuter, 0.8, {
		drawSVG: '0% 100%',
		ease: initEasing
	}, "-=0.6")

	.staggerTo($dialMarkers, 0.8, {
		cycle: {
			rotation: function(i) { return 180 - 36*i; }
		},
		ease: Power2.easeOut
	}, 0.1, "-=0.4")

	.staggerFrom($dialMarkerNums, 0.8, {
		autoAlpha: 0,
		x: 20,
		ease: Power2.easeOut
	}, 0.1, "-=0.6")

	.from($dragLine, 0.3, {
		scaleY: 0,
		transformOrigin: "0% 100%",
		ease: Power2.easeIn
	}, "-=1.2")

	.from($dragInner, 0.5, {
		scale: 0,
		y: 20,
		transformOrigin: "center center",
		ease: Elastic.easeOut.config(0.9, 0.3)
	}, "-=0.9")

	.staggerFrom($resultsText, 0.8, {
		autoAlpha: 0,
		y: 20,
		ease: Power2.easeOut
	}, 0.1, "-=1.4")

	.to($trackPerc, 0.8, {
		drawSVG: '0% 10%', // animate to the default 10%
		ease: initEasing
	}, "-=0.4")

	.to($drag, 0.8, {
		rotation: 36, // animate to the default 10%
		ease: initEasing,
		onUpdate: function() {
			dragUpdate();
		}
	}, "-=1.0");


Draggable.create($drag, {
	type:"rotation",
	throwProps:true,
	bounds:{ maxRotation:maxRotation, minRotation:0 },
	snap:function(endValue) { 
		return Math.round(endValue / rotationSnap) * rotationSnap;
	},
	onDrag:dragUpdate,
	onThrowUpdate:dragUpdate,
	allowNativeTouchScrolling:false
})

function dragUpdate() {
	var val = ($drag[0]._gsTransform.rotation);
	var percentage = Math.round((val/180)*100/2);
	savings = Math.round(percentage * decreaseScale * tCost); // 1% savings = 0.006 x total infections cost
	if(savings < 0) {
		savings = 0;
	}
	if(percentage > 50) {
		percentage = 50;
	}
	else if(percentage < 0){
		percentage = "0";
	}
	$perc.text(percentage);
	TweenMax.set($trackPerc, {
		drawSVG: '0% '+ val/180*100/2 +'%'
	});
	$saving.text(savings.toLocaleString('en', {maximumSignificantDigits : 21})); // change! Locale not massively compatible yet especially on mobile
}

console.clear();
              
            
!
999px

Console