HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div class="services">
<svg width="664" height="1216" viewBox="0 0 664 1216">
<g id="layer1">
<path id="path1" d="M22.9998 1C22.9998 1 649.558 119 663 589.542C655.833 1135 1 1215 1 1215" stroke="#29A0EC" fill="none" />
</g>
<g id="oval" fill="none">
<path id="Oval" fill-rule="evenodd" clip-rule="evenodd" d="M84 90C87.3137 90 90 87.3137 90 84C90 80.6863 87.3137 78 84 78C80.6863 78 78 80.6863 78 84C78 87.3137 80.6863 90 84 90Z" fill="#29A0EC" />
<path id="Oval_2" opacity="0.3" fill-rule="evenodd" clip-rule="evenodd" d="M83.5 96C90.4036 96 96 90.4036 96 83.5C96 76.5964 90.4036 71 83.5 71C76.5964 71 71 76.5964 71 83.5C71 90.4036 76.5964 96 83.5 96Z" fill="#29A0EC" />
<path id="Oval_3" fill-rule="evenodd" clip-rule="evenodd" d="M83.5 101C93.165 101 101 93.165 101 83.5C101 73.835 93.165 66 83.5 66C73.835 66 66 73.835 66 83.5C66 93.165 73.835 101 83.5 101Z" stroke="#00A031" stroke-opacity="0.16" />
<path id="Oval_4" fill-rule="evenodd" clip-rule="evenodd" d="M83.5 106C95.9264 106 106 95.9264 106 83.5C106 71.0736 95.9264 61 83.5 61C71.0736 61 61 71.0736 61 83.5C61 95.9264 71.0736 106 83.5 106Z" stroke="#00A031" stroke-opacity="0.13" />
<path id="Oval_5" fill-rule="evenodd" clip-rule="evenodd" d="M83.5 111C98.6878 111 111 98.6878 111 83.5C111 68.3122 98.6878 56 83.5 56C68.3122 56 56 68.3122 56 83.5C56 98.6878 68.3122 111 83.5 111Z" stroke="#00A031" stroke-opacity="0.12" />
<path id="Oval_6" fill-rule="evenodd" clip-rule="evenodd" d="M83.5 117C102.002 117 117 102.002 117 83.5C117 64.9985 102.002 50 83.5 50C64.9985 50 50 64.9985 50 83.5C50 102.002 64.9985 117 83.5 117Z" stroke="#00A031" stroke-opacity="0.11" />
<path id="Oval_7" fill-rule="evenodd" clip-rule="evenodd" d="M83.5 123C105.315 123 123 105.315 123 83.5C123 61.6848 105.315 44 83.5 44C61.6848 44 44 61.6848 44 83.5C44 105.315 61.6848 123 83.5 123Z" stroke="#00A031" stroke-opacity="0.1" />
<path id="Oval_8" fill-rule="evenodd" clip-rule="evenodd" d="M84 131C109.957 131 131 109.957 131 84C131 58.0426 109.957 37 84 37C58.0426 37 37 58.0426 37 84C37 109.957 58.0426 131 84 131Z" stroke="#00A031" stroke-opacity="0.08" />
<path id="Oval_9" fill-rule="evenodd" clip-rule="evenodd" d="M83.5 139C114.152 139 139 114.152 139 83.5C139 52.8482 114.152 28 83.5 28C52.8482 28 28 52.8482 28 83.5C28 114.152 52.8482 139 83.5 139Z" stroke="#00A031" stroke-opacity="0.06" />
<path id="Oval_10" fill-rule="evenodd" clip-rule="evenodd" d="M83.5 147C118.57 147 147 118.57 147 83.5C147 48.4299 118.57 20 83.5 20C48.4299 20 20 48.4299 20 83.5C20 118.57 48.4299 147 83.5 147Z" stroke="#00A031" stroke-opacity="0.04" />
<path id="Oval_11" fill-rule="evenodd" clip-rule="evenodd" d="M83.5 156C123.541 156 156 123.541 156 83.5C156 43.4594 123.541 11 83.5 11C43.4594 11 11 43.4594 11 83.5C11 123.541 43.4594 156 83.5 156Z" stroke="#00A031" stroke-opacity="0.03" />
<path id="Oval_12" fill-rule="evenodd" clip-rule="evenodd" d="M83.5 166C129.063 166 166 129.063 166 83.5C166 37.9365 129.063 1 83.5 1C37.9365 1 1 37.9365 1 83.5C1 129.063 37.9365 166 83.5 166Z" stroke="#00A031" stroke-opacity="0.03" />
</g>
</svg>
</div>
.services {
display: flex;
padding-top: 200px;
padding-bottom: 200px;
}
svg {
margin: 0 auto;
}
function positionOval() {
var scrollY = window.scrollY || window.pageYOffset;
var maxScrollY = document.documentElement.scrollHeight - window.innerHeight;
var path = document.getElementById("path1");
// Calculate distance along the path the car should be for the current scroll amount
var pathLen = path.getTotalLength();
var dist = pathLen * scrollY / maxScrollY;
var pos = path.getPointAtLength(dist);
// Calculate position a little ahead of the car (or behind if we are at the end), so we can calculate car angle
if (dist + 1 <= pathLen) {
var posAhead = path.getPointAtLength(dist + 1);
var angle = Math.atan2(posAhead.y - pos.y, posAhead.x - pos.x);
} else {
var posBehind = path.getPointAtLength(dist - 1);
var angle = Math.atan2(pos.y - posBehind.y, pos.x - posBehind.x);
}
// Position the car at "pos" totated by "angle"
var oval = document.getElementById("oval");
var oval_bbox = oval.getBBox();
var half_width = oval_bbox.width / 2;
var half_height = oval_bbox.height / 2;
oval.setAttribute("transform",
"translate(" + (pos.x - half_width) + "," + (pos.y - half_height) + ") " +
"rotate(" + angle / Math.PI * 180 + "," + half_width + "," + half_height + ")");
}
function rad2deg(rad) {
return 180 * rad / Math.PI;
}
// Reposition car whenever there is a scroll event
window.addEventListener("scroll", positionOval);
// Position the car initially
positionOval();
Also see: Tab Triggers