<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<!DOCTYPE html><html class=''>
<head><script src='//production-assets.codepen.io/assets/editor/live/console_runner-079c09a0e3b9ff743e39ee2d5637b9216b3545af0de366d4b9aad9dc87e26bfd.js'></script><script src='//production-assets.codepen.io/assets/editor/live/events_runner-73716630c22bbc8cff4bd0f07b135f00a0bdc5d14629260c3ec49e5606f98fdd.js'></script><script src='//production-assets.codepen.io/assets/editor/live/css_live_reload_init-2c0dc5167d60a5af3ee189d570b1835129687ea2a61bee3513dee3a50c115a77.js'></script><meta charset='UTF-8'><meta name="robots" content="noindex"><link rel="shortcut icon" type="image/x-icon" href="//production-assets.codepen.io/assets/favicon/favicon-8ea04875e70c4b0bb41da869e81236e54394d63638a1ef12fa558a4a835f1164.ico" /><link rel="mask-icon" type="" href="//production-assets.codepen.io/assets/favicon/logo-pin-f2d2b6d2c61838f7e76325261b7195c27224080bc099486ddd6dccb469b8e8e6.svg" color="#111" /><link rel="canonical" href="https://codepen.io/Twixes/pen/xZQVQW?limit=all&page=30&q=box" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css'><link rel='stylesheet prefetch' href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:600|Roboto:700i'>
<style class="cp-pen-styles">html,
body {
width: 100%;
height: 100%;
margin: 0;
background: #fff;
}
#headlight-field {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
width: 100%;
height: 100%;
}
#headlight-text {
will-change: text-shadow;
color: #fff;
font: 700 italic 24vmin "Roboto";
text-rendering: optimizeLegibility;
}
</style></head><body>
<div id="headlight-field">
<div id="headlight-text">Twixes</div>
</div>
<script src='//production-assets.codepen.io/assets/common/stopExecutionOnTimeout-b2a7b3fe212eaa732349046d8416e00a9dec26eb7fd347590fbced3ab38af52e.js'></script><script src='https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>
<script >// # WORKS WELL ONLY ON LARGE TEXT
// # quick glossary:
// outerId = the ID of the mouse tracking plane (can be the same as innerId)
// innerId = the ID of the shaded element (can be the same as outerId)
// shadowType = determines if the shadow is a text or box one (valid values: 'text', 'box')
// # Headlight's shading function
function HeadlightShade(x, y, innerId, shadowType, shadowSmoothness, shadowLengthLimit, shadowScattering, shadowOpacity) {
var shadowSettings = [];
var shadows = [];
var shadow;
x = x - $('#' + innerId).offset().left - $('#' + innerId).width() / 2;
y = y - $('#' + innerId).offset().top - $('#' + innerId).height() / 2;
// ## Y axis shadow length limiting
if (y < 0 && y < -shadowLengthLimit) {
y = -shadowLengthLimit;
} else if (y > shadowLengthLimit) {
y = shadowLengthLimit;
}
// ## X axis shadow length limiting
if (x < 0 && x < -shadowLengthLimit) {
x = -shadowLengthLimit;
} else if (x > shadowLengthLimit) {
x = shadowLengthLimit;
}
// ## configuring shadows
for (i = 0; i < shadowSmoothness; i++) {if (window.CP.shouldStopExecution(1)){break;}
shadowSettings.push({
x: (-x) / shadowSmoothness * i,
y: (-y) / shadowSmoothness * i,
width: shadowScattering * i,
opacity: shadowOpacity - (shadowOpacity / shadowSmoothness ) * i
});
}
window.CP.exitedLoop(1);
// ## setting shadows up
for (i in shadowSettings) {if (window.CP.shouldStopExecution(2)){break;}
shadows.push(shadowSettings[i].x + 'px ' + shadowSettings[i].y + 'px ' + shadowSettings[i].width + 'px rgba(0, 0, 0,' + shadowSettings[i].opacity + ')');
}
window.CP.exitedLoop(2);
// ## applying shadows
if (shadowType === 'text') {
$('#' + innerId).css({
'text-shadow': shadows.join(', ')
});
} else if (shadowType === 'box') {
$('#' + innerId).css({
'box-shadow': shadows.join(', ')
});
}
}
// # mouse tracking function
function HeadlightTrack(outerId, innerId, shadowType, shadowSmoothness, shadowLengthLimit, shadowScattering, shadowOpacity) {
// ## shade basing on the cursor's position
$('#' + outerId).mousemove(function (e) {
HeadlightShade(e.pageX, e.pageY, innerId, shadowType, shadowSmoothness, shadowLengthLimit, shadowScattering, shadowOpacity);
});
// ## default shading settings (used when no input was provided)
HeadlightShade(0, 70, innerId, shadowType, shadowSmoothness, shadowLengthLimit, shadowScattering, shadowOpacity);
}
// # Headlight activation and configuration
HeadlightTrack('headlight-field', 'headlight-text', 'text', 20, 175, 8, 0.275);
//# sourceURL=pen.js
</script>
</body></html>