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.
<html>
<head>
<title> Changing Sky Source</title>
<!-- --------- IMPORTED LIBRARIES ------>
<script src="https://aframe.io/releases/0.6.0/aframe.min.js"></script>
</head>
<body>
<a-scene> <!-- Creating scene -->
<!-- --------- ASSETS --------- -->
<!-- Asset links. -->
<a-assets>
<img id="background_inside_house" crossorigin="anonymous" src="https://cdn.glitch.com/e6225ccd-c32e-4cf8-b039-e78814a8cb78%2Fbg-3.jpg?1498128817274">
<img id="chinese_temple" crossorigin="anonymous" src="https://cdn.glitch.com/e6225ccd-c32e-4cf8-b039-e78814a8cb78%2Fbg-1.jpg?1498129063299">
</a-assets>
<!-- --------- SKY --------- -->
<a-sky id="background-img" src="#background_inside_house" theta-length="130"></a-sky>
<!--
You can use the keys W,A,S,D to move around
But for that you need to change Theta length (cylinder radius)
This will create a "hole" in the floor of the image -->
<a-plane id="btn_trigger" position="3 3 -9" height="2" width="5" rotation="0 0 0" color="#e21d2d">
<!-- a-plane is like a rectangle.
I use them as buttons only to keep some of the usual UI conventions. Even though you are on a new medium, if you want users to understand your applocation/website you need to use some of the expected norms and rules of UI/UX
The a-plane tag has a lot of possibilities in terms of properties, check them out here https://aframe.io/docs/0.6.0/primitives/a-plane.html-->
<a-text value="Trip to China" position="0 0 0" scale="2 2 2" align="center" ></a-text> <!--Since this is inside the plane, the text position is relative to the plain's position
If you use the property align wisely, you don't need to experiment with position
Text documentation: https://aframe.io/docs/0.6.0/primitives/a-text.html-->
</a-plane>
<!-- --------- CAMERA AND CURSOR --------- -->
<a-camera look-controls-enabled wasd-controls-enabled position="0 1 4">
<!--Enabling gaze controls = look-controls-enabled
Enabling key control= wasd-controls-enabled
You can use the keys W,A,S,D to move around-->
<a-cursor position="0 0 -3"
geometry="primitive: ring; radiusOuter: 0.030; radiusInner: 0.020;"
material="color: #11d8c4; shader: flat"
fuse="true" timeout="10"> <!--Giving our cursor properties-->
<!--The timeout defines how long it'll take to trigger something on fuse-->
<a-animation begin="click" easing="ease-in" attribute="color"
fill="backwards" from="#11d8c4" to="#ffffff"></a-animation> <!--Animating the cursor while you click-->
<a-animation begin="cursor-hovering" easing="ease-in" attribute="scale"
fill="forwards" from="1 1 1" to="0.5 0.5 0.5"></a-animation> <!--Animating the cursor while you hover-->
</a-cursor> <!--These animations serve for the purposes of debugging and better UX
If there is something you want to be followed by the cursor, draw it below-->
</a-camera>
</a-scene>
<!-- Closing scene -->
</body>
</html>
<!-- --------- JAVASCRIPT --------- -->
//-- --------- CHANGE BG ON BUTTON HOVER JS ---------
function ChangeBackground() { //Using full JS in order to keep the code tidy and understandable
//Jquery is good as well, but I have a tendency to mix it with Js, so that creates a few errors
var trigger = document.getElementById("btn_trigger"); // <a-plane id="btn_trigger">
var sky = document.getElementById("background-img"); // <a-sky id="background-img">
trigger.addEventListener('mouseenter', function () {//open event listener
//here we change the sky src IF the mouse has entered the plane with the id btn_trigger
sky.setAttribute('src','#chinese_temple');
}); // Close event listener
trigger.addEventListener('mouseleave', function () { //open event listener
//here we change the sky src back to the original image once mouse has left the plane with the id btn_trigger
//in case you don't want to change back to the original image, just remove the whole mouseleave event
sky.setAttribute('src','#background_inside_house');
}); // Close event listener
}//Close function
ChangeBackground(); //calling the function
Also see: Tab Triggers