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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<head>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<!--==============レイアウトを制御する独自のCSSを読み込み===============-->
<link href="https://assets.codepen.io/6329135/reset04.css" rel="stylesheet">
</head>
<body>
<div id="wrapper">
<p>※参照 <a href="https://jsfiddle.net/39we73t1/" target="_blank">https://jsfiddle.net/39we73t1/</a></p>
<canvas id="waveCanvas"></canvas>
<!--/wrapper-->
</div>
</body>
@charset "utf-8";
/*========= レイアウトのためのCSS ===============*/
#wrapper {
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
position: relative;
}
/*========= waveを描画するエリア設定 ===============*/
canvas {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
}
var unit = 100,
canvasList, // キャンバスの配列
info = {}, // 全キャンバス共通の描画情報
colorList; // 各キャンバスの色情報
/**
* Init function.
*
* Initialize variables and begin the animation.
*/
function init() {
info.seconds = 0;
info.t = 0;
canvasList = [];
colorList = [];
// canvas1個めの色指定
canvasList.push(document.getElementById("waveCanvas"));
colorList.push(["#43c0e4"]);
// 各キャンバスの初期化
for (var canvasIndex in canvasList) {
var canvas = canvasList[canvasIndex];
canvas.width = document.documentElement.clientWidth; //Canvasのwidthをウィンドウの幅に合わせる
canvas.height = 300; //波の高さ
canvas.contextCache = canvas.getContext("2d");
}
// 共通の更新処理呼び出し
update();
}
function update() {
for (var canvasIndex in canvasList) {
var canvas = canvasList[canvasIndex];
// 各キャンバスの描画
draw(canvas, colorList[canvasIndex]);
}
// 共通の描画情報の更新
info.seconds = info.seconds + 0.014;
info.t = info.seconds * Math.PI;
// 自身の再起呼び出し
setTimeout(update, 35);
}
/**
* Draw animation function.
*
* This function draws one frame of the animation, waits 20ms, and then calls
* itself again.
*/
function draw(canvas, color) {
// 対象のcanvasのコンテキストを取得
var context = canvas.contextCache;
// キャンバスの描画をクリア
context.clearRect(0, 0, canvas.width, canvas.height);
//波を描画 drawWave(canvas, color[数字(波の数を0から数えて指定)], 透過, 波の幅のzoom,波の開始位置の遅れ )
drawWave(canvas, color[0], 1, 3, 0); //drawWave(canvas, color[0],0.5, 3, 0);とすると透過50%の波が出来る
}
/**
* 波を描画
* drawWave(色, 不透明度, 波の幅のzoom, 波の開始位置の遅れ)
*/
function drawWave(canvas, color, alpha, zoom, delay) {
var context = canvas.contextCache;
context.fillStyle = color; //塗りの色
context.globalAlpha = alpha;
context.beginPath(); //パスの開始
drawSine(canvas, info.t / 0.5, zoom, delay);
context.lineTo(canvas.width + 10, canvas.height); //パスをCanvasの右下へ
context.lineTo(0, canvas.height); //パスをCanvasの左下へ
context.closePath(); //パスを閉じる
context.fill(); //波を塗りつぶす
}
/**
* Function to draw sine
*
* The sine curve is drawn in 10px segments starting at the origin.
* drawSine(時間, 波の幅のzoom, 波の開始位置の遅れ)
*/
function drawSine(canvas, t, zoom, delay) {
var xAxis = Math.floor(canvas.height / 2);
var yAxis = 0;
var context = canvas.contextCache;
// Set the initial x and y, starting at 0,0 and translating to the origin on
// the canvas.
var x = t; //時間を横の位置とする
var y = Math.sin(x) / zoom;
context.moveTo(yAxis, unit * y + xAxis); //スタート位置にパスを置く
// Loop to draw segments (横幅の分、波を描画)
for (i = yAxis; i <= canvas.width + 10; i += 10) {
x = t + (-yAxis + i) / unit / zoom;
y = Math.sin(x - delay) / 3;
context.lineTo(i, unit * y + xAxis);
}
}
init();
Also see: Tab Triggers