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.content.js-Character_Change
div.character.js-Character_Target
div.egg
img(src="https://dl.dropbox.com/s/k8c2ohkz66sykbo/egg.png?dl=0" alt="卵")
div.chick
img(src="https://dl.dropbox.com/s/9tl5urilcpo60mt/chick.png?dl=0" alt="ひよこ")
div.btn.js-Character_Switcher クリック!!
div.canvas.js-Character_Canvas
.content{
padding: 40px 0 0;
position: relative;
z-index: 1;
.character{
width: 200px;
height: 200px;
margin: 0 auto;
position: relative;
> div{
margin: 0 auto;
position: absolute;
left: 0;
right: 0;
&.off{
animation: scale-down .1s ease-in forwards;
}
&.on{
animation: scale-easeOutElastic .75s ease-in forwards;
}
img{
width: 100%;
height: auto;
}
}
.egg{
width: 120px;
top: 40px;
}
.chick{
width: 200px;
top: 0;
transform: scale(0);
}
}
.btn{
width: 200px;
height: 50px;
margin: 40px auto 0;
display: flex;
align-items: center;
justify-content: center;
background: #ffe384;
border-radius: 25px;
box-shadow: 0 4px 0 0 #fcbe03;
cursor: pointer;
font-size: 16px;
font-weight: bold;
color: #333;
&:hover{
transform: translateY(4px);
box-shadow: none;
}
}
.canvas{
width: 500px;
height: 500px;
position: absolute;
top: -90px;
left: 50%;
transform: translateX(-50%);
z-index: -1;
}
}
@keyframes scale-down {
0% { transform: scale(1); }
100% { transform: scale(0); }
}
@keyframes scale-easeOutElastic {
0% { transform: scale(0); }
16% { transform: scale(1.1); }
28% { transform: scale(.9); }
44% { transform: scale(1.025); }
59% { transform: scale(.975); }
73% { transform: scale(1.0125); }
88% { transform: scale(1); }
100% { transform: scale(1); }
}
$('.js-Character_Change').each(function(){
const $this = $(this);
const $target = $this.children('.js-Character_Target');
const $switcher = $this.children('.js-Character_Switcher');
const $canvas = $this.children('.js-Character_Canvas');
let canvasWidth = $canvas.innerWidth();
let canvasHeight = $canvas.innerHeight();
// アプリケーションの作成
const app = new PIXI.Application(canvasWidth, canvasHeight, {transparent : true});
$canvas.append(app.view);
// コンテナの作成
let container = new PIXI.Container();
// ステージに反映
app.stage.addChild(container);
container.x = 0;
container.y = 0;
// 表示をするパーティクルの数
let totalParticle = 50;
// 画像配列
let images = ['https://dl.dropbox.com/s/eejj0fryiojjcfw/star.png?dl=0']
// クリック処理
let index = 0;
$switcher.on('click',function(){
// 切り替え処理
const targetLength = $target.children().length - 1;
index+=1;
if(index > targetLength){
index = 0;
}
$target.children('div').addClass('off').removeClass('on');
$target.children('div').eq(index).removeClass('off').addClass('on');
// パーティクル用の配列
const particles = [];
// totalParticle回数分ループ
for (let i = 0; i < totalParticle; i++) {
// パーティクルの画像設定
let n = Math.floor(Math.random() * images.length);
const particle = PIXI.Sprite.from(images[n]);
// パーティクルの中心をきめる
particle.anchor.set(0.5);
// 透明度
particle.alpha = 1;
// サイズをランダムにきめる
const max = app.screen.width * 0.000166666666667;
const size = Math.random() * max;
particle.scale.set(size);
// パーティクルの位置をcanvasの中心に
particle.x = app.screen.width / 2;
particle.y = app.screen.height / 2;
// 速度と向き
particle.vx = app.screen.width * 0.02 * (Math.random() - 0.5); // 0~1 - .5 = -.5 ~ .5;
particle.vy = app.screen.width * 0.02 * (Math.random() - 0.5);
// 寿命
particle.life = 100;
// 生成されたパーティクルの配列をpushして簡単にアクセスできるようにします
particles.push(particle);
// コンテナに反映
container.addChild(particle);
}
// アニメーションフレーム毎の処理を指定
app.ticker.add(function() {
// 画像を繰り返し処理して位置を更新する
for (let i = 0; i < particles.length; i++) {
//配列を代入
const particle = particles[i];
// 透明度
particle.alpha -= 0.01;
// サイズ変化
particle.scale.x *= .99;
particle.scale.y *= .99;
// 回転
particle.rotation += 0.1;
// 寿命
particle.life -= 1;
// 摩擦
particle.vx *= .98;
particle.vy *= .98;
// 速度を位置に足していく
particle.x += particle.vx;
particle.y += particle.vy;
if (particle.life <= 0) {
// コンテナから削除
container.removeChild(particle);
// 配列からも削除(i番目から1個削除)
particles.splice(i, 1);
}
}
});
});
});
Also see: Tab Triggers