JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<body>
<div class="mv">
<p class="text"><span>i</span><span>n</span><span>t</span><span>e</span><span>r</span><span>a</span><span>c</span><span>t</span><span>i</span><span>v</span><span>e</span></p>
</div>
<div class="attention"><p>SCROLL</p></div>
<div class="dummy_height"></div>
</body>
* {
box-sizing: border-box;
}
body, html {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.mv {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
overflow: hidden;
background-color: #1b2920;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.text {
font-size: 0;
font-style: italic;
color: #FFF;
}
.text span {
font-size: 12vw;
display: inline-block;
text-decoration: underline;
}
.dummy_height {
position: absolute;
top:5000px;
width: 1px;
height: 1px;
}
.attention {
position: fixed;
width: 100%;
height: 100%;
color: #FFF;
font-weight: bold;
font-size: 18px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-end;
letter-spacing: 0.05em;
}
// 動かすターゲットとか入れておく
arr = [];
init();
// 初期設定
function init() {
$('.text span').each(function(i,e) {
var el = $(e);
// 移動の方向をバラバラに
var kakeY = 1;
if(i % 2 == 0) {
kakeY *= -1;
}
var o = {
kakeY:kakeY,
y:0,
el:el
};
arr.push(o);
});
}
// 毎フレーム実行
window.requestAnimationFrame(update);
function update() {
// ステージサイズ
var sw = window.innerWidth;
var sh = window.innerHeight;
// スクロール位置
var scroll = $(window).scrollTop();
// スクロール進捗率 0 ~ 1
var scrollP = scroll / ($(document).height() - sh);
var len = arr.length;
for(var i = 0; i < len; i++) {
var o = arr[i];
// スクロール進捗率を順番に分配してく
var size = 1 / len;
var offset = 0.8; // ちょっと食い気味に入ってくるように
var p = map(scrollP, 0, 1, size * offset * i, size * i + size);
// イージングさせるのでまずこっちを更新
var tgY = o.kakeY * sh * 0.5 * (1 - p);
o.y += (tgY - o.y) * 0.1;
// DOMに反映
TweenMax.set(o.el, {
y:o.y,
opacity:p //最初は見えないようにするため
});
}
window.requestAnimationFrame(update);
}
// ----------------------------------------
// 度からラジアンに変換
// @val : 度
// ----------------------------------------
function radian(val) {
return val * Math.PI / 180;
}
// ----------------------------------------
// ラジアンから度に変換
// @val : ラジアン
// ----------------------------------------
function degree(val) {
return val * 180 / Math.PI;
}
// ----------------------------------------
// minからmaxまでランダム
// ----------------------------------------
function random(min, max) {
return Math.random() * (max - min) + min;
}
// ----------------------------------------
// 範囲変換
// @val : 変換したい値
// @toMin : 変換後の最小値
// @toMax : 変換後の最大値
// @fromMin : 変換前の最小値
// @fromMax : 変換前の最大値
// ----------------------------------------
function map(val, toMin, toMax, fromMin, fromMax) {
if(val <= fromMin) {
return toMin;
}
if(val >= fromMax) {
return toMax;
}
p = (toMax - toMin) / (fromMax - fromMin);
return ((val - fromMin) * p) + toMin;
}
Also see: Tab Triggers