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.
<svg id="speelVeld" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 1366 706.8" style="enable-background:new 0 0 1366 706.8;" xml:space="preserve">
<style type="text/css">
.st0{fill:#FF5000;}
.st1{fill:#3535D4;}
.st2{fill:none;stroke:#3535D4;stroke-width:1.5;stroke-miterlimit:10;}
.st3{fill:#ffffff;}
</style>
<g id="speelveldClick">
<rect x="30" y="29" class="st0" width="1306" height="645.7"/>
</g>
<g id="moveX">
<path class="st1" d="M-85.8,29V9h171v20H-85.8z M85.8,694.7v-20h-171v20H85.8z"/>
<!-- <line class="st2" x1="0" y1="59" x2="0" y2="645.2"/> -->
</g>
<g id="moveY">
<path class="st1" d="M30,85H10V-86h20V85z M1356-86h-20V85h20V-86z"/>
<!-- <line class="st2" x1="1306" y1="0" x2="60" y2="0"/> -->
</g>
<circle id="ball" class="st3" cx="683" cy="353.4" r="18"/>
</svg>
body{
background-color: #FF5000;
}
#speelveldClick{
cursor: pointer;
}
//refresh when the ball is out of sight
var ease = 0.15;
var speelVeld = document.querySelector("#speelVeld");
var moveX = document.querySelector("#moveX");
var moveY = document.querySelector("#moveY");
var bg = document.querySelector("#speelveldClick");
var mouse = speelVeld.createSVGPoint();
var pos = { x: 0, y: 0 };
var fieldBox = speelVeld.getBBox();
var Xbox = moveX.getBBox();
var Ybox = moveY.getBBox();
var viewXhalf = fieldBox.width/2;
var viewYhalf = fieldBox.height/2;
var xboxHalf = Xbox.width/4;
var yboxHalf = Ybox.height/4;
var ball = document.querySelector("#ball");
var ballBox = ball.getBBox();
var setBall = ballBox.width/2;
var tlBall = new TimelineMax();
/*
var tlX = new TimelineMax();
var tlY = new TimelineMax();
window.onload = function(e){
tlX.set(moveX, {
x: viewXhalf-xboxHalf
});
tlY.set(moveY, {
y: viewYhalf-yboxHalf
});
}
*/
bg.onclick = function(e){
mouse.x = e.clientX;
mouse.y = e.clientY;
};
TweenMax.ticker.addEventListener("tick", update);
function update() {
var point = mouse.matrixTransform(speelVeld.getScreenCTM().inverse());
pos.x += (point.x - pos.x) * ease;
pos.y += (point.y - pos.y) * ease;
TweenLite.set(moveX, {
x: pos.x
});
TweenLite.set(moveY, {
y: pos.y
});
}
TweenMax.ticker.addEventListener("tick", mBall);
function mBall() {
tlBall
.set(ball, {x: setBall ++}); //is there a way to speed this up?
}
//below is a quick attempt to reset the ball if it's beyond the viewbox of the svg; I did not figure out yet how to do that
/*
function resetBall(){
if ballBox.x => fieldBox.x{
tlBall.kill();
}
}
*/
Also see: Tab Triggers