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.
<p style="width: 100%; font-size: 20px; line-height: 30px; text-align: center; margin-top: 48vh;">下にスクロールしてみてください。</p>
<div class="fadeAnimation">
<div class="fadeAnimation__item js-fadeAnimation fadeIn">
<div class="fadeAnimation__itemInner">
<p class="fadeAnimation__text">フェードイン</p>
</div>
</div><!-- /.fadeAnimation__item -->
<div class="fadeAnimation__item js-fadeAnimation fadeUp delay04s">
<div class="fadeAnimation__itemInner">
<p class="fadeAnimation__text">フェードイン(下から上へ)</p>
</div>
</div><!-- /.fadeAnimation__item -->
<div class="fadeAnimation__item js-fadeAnimation fadeDown delay2s">
<div class="fadeAnimation__itemInner">
<p class="fadeAnimation__text">フェードイン(上から下へ)</p>
</div>
</div><!-- /.fadeAnimation__item -->
<div class="fadeAnimation__item js-fadeAnimation fadeRight delay04s">
<div class="fadeAnimation__itemInner">
<p class="fadeAnimation__text">フェードイン(左から右へ)</p>
</div>
</div><!-- /.fadeAnimation__item -->
<div class="fadeAnimation__item js-fadeAnimation fadeLeft delay04s">
<div class="fadeAnimation__itemInner">
<p class="fadeAnimation__text">フェードイン(右から左へ)</p>
</div>
</div><!-- /.fadeAnimation__item -->
</div><!-- /.fadeAnimation -->
/*------------------------------
fadeAnimation デモ用装飾
------------------------------*/
.fadeAnimation {
display: flex;
flex-flow: row wrap;
max-width: 96%;
margin: 60vh auto;
}
.fadeAnimation__item {
width: 32%;
height: 40vh;
background-color: #202f55;
margin: 0 auto 60vh;
}
.fadeAnimation__itemInner {
display: table;
width: 100%;
height: 100%;
}
.fadeAnimation__text {
display: table-cell;
color: #ffffff;
font-size: 18px;
text-align: center;
vertical-align: middle;
padding: 10px;
box-sizing: border-box;
}
/*------------------------------
アニメーション
------------------------------*/
.fadeIn {
opacity: 0;
}
.fadeUp {
opacity: 0;
transform: translateY(50px);
}
.fadeDown {
opacity: 0;
transform: translateY(-50%);
}
.fadeRight {
opacity: 0;
transform: translateX(-50%);
}
.fadeLeft {
opacity: 0;
transform: translateX(50%);
}
.delay01s {
animation-delay: 0.1s;
}
.delay02s {
animation-delay: 0.2s;
}
.delay03s {
animation-delay: 0.3s;
}
.delay04s {
animation-delay: 0.4s;
}
.delay05s {
animation-delay: 0.5s;
}
.delay06s {
animation-delay: 0.6s;
}
.delay07s {
animation-delay: 0.7s;
}
.delay08s {
animation-delay: 0.8s;
}
.delay09s {
animation-delay: 0.9s;
}
.delay1s {
animation-delay: 1s;
}
.delay2s {
animation-delay: 2s;
}
.fadeIn.is-animated {
animation-name: fadeIn;
animation-duration: 1s;
animation-fill-mode: both;
}
.fadeUp.is-animated {
animation-name: fadeUp;
animation-duration: 1s;
animation-fill-mode: both;
}
.fadeDown.is-animated {
animation-name: fadeDown;
animation-duration: 1s;
animation-fill-mode: both;
}
.fadeRight.is-animated {
animation-name: fadeRight;
animation-duration: 1s;
animation-fill-mode: both;
}
.fadeLeft.is-animated {
animation-name: fadeLeft;
animation-duration: 1s;
animation-fill-mode: both;
}
@keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes fadeUp {
0% {
opacity: 0;
transform: translateY(50px);
}
100% {
opacity: 1;
transform: translateY(0px);
}
}
@keyframes fadeDown {
0% {
opacity: 0;
transform: translateY(-50px);
}
100% {
opacity: 1;
transform: translateY(0px);
}
}
@keyframes fadeRight {
0% {
opacity: 0;
transform: translateX(-50%);
}
100% {
opacity: 1;
transform: translateX(0px);
}
}
@keyframes fadeLeft {
0% {
opacity: 0;
transform: translateX(50%);
}
100% {
opacity: 1;
transform: translateX(0px);
}
}
// Scroll fade-in animation
(function () { // 即時実行関数(グローバル汚染対策)
let i = 0; // for文用変数の定義
let el = {}; // 配列・変数用(巻き上げ防止の為、冒頭にて宣言)
// DOM読み込み後のタイミングで処理
document.addEventListener('DOMContentLoaded', function () {
el.targetElement = document.querySelectorAll('.js-fadeAnimation'); // フェードアニメーション表示させる要素のセレクタ指定
el.firstDisplayOnlyFlag = false; // フェードアニメーション表示を1回のみにするかの判定フラグ(true:1回のみ、false:複数回)
}, false);
// スクロール時の処理
window.addEventListener('scroll', function () {
scrollAnimationFnc(); // スクロールアニメーション用関数の実行
}, false);
// 向き切り替え(リサイズ)時の処理
window.addEventListener('resize', function () {
scrollAnimationFnc(); // スクロールアニメーション用関数の実行
}, false);
// スクロールアニメーション用関数
function scrollAnimationFnc () {
el.scrollValue = window.pageYOffset || document.documentElement.scrollTop; // 現在のスクロール量の取得
el.documentHeight = document.documentElement.clientHeight; // ドキュメント全体の高さ(スクロールバー含ない)を取得(表示領域部分の高さ)
for (i = 0; i < el.targetElement.length; ++i) {
el.clientRect = el.targetElement[i].getBoundingClientRect(); // 対象要素のViewpor(ビューポート)に対する相対位置に関する情報を取得
el.targetPosition = el.clientRect.top + el.scrollValue; // 対象要素の位置座標を取得
el.targetHeight = el.targetElement[i].offsetHeight; // 対象要素のborder、paddingを含んだ高さを取得
if (el.scrollValue < el.targetPosition - el.documentHeight || el.scrollValue > el.targetPosition + el.targetHeight) {
// ドキュメント全体の高さ(スクロールバー含ない)内(表示領域)に対象要素の位置が入っていなければ処理
if (!el.firstDisplayOnlyFlag) {
// 判定フラグが「false(複数回)」の場合に処理
el.targetElement[i].classList.remove('is-animated'); // 対象要素から「is-animated」classを削除する
} else {
// 判定フラグが「true(1回のみ)」の場合に処理
return false; // 処理を中断
}
} else {
// ドキュメント全体の高さ(スクロールバー含ない)内(表示領域)に対象要素の位置が入っていれば処理
el.targetElement[i].classList.add('is-animated'); // 対象要素に「is-animated」classを付与する
}
}
}
}());
Also see: Tab Triggers