実装例:詳しくはこのページのリバースエンジニアリングしてください。
-
- 2015年
- ECMAScript 2015 (ECMA-262, 6th edition, June 2015) クラス、モジュール、イテレータ、for/ofループ、Pythonスタイルのジェネレータ、アロー関数、2進数および8進数の整数リテラル、Map、Set、WeakMap、WeakSet、プロキシ、テンプレート文字列、let、const、型付き配列、デフォルト引数、Symbol、Promise、分割代入、可変長引数
-
- 2016年
- ECMAScript 2016 (ECMA-262, 7th edition, June 2016)冪乗演算子、Array.prototype.includes
-
- 2017年
- ECMAScript 2017 (ECMA-262, 8th edition, June 2017) 非同期関数 (async/await)、SharedArrayBufferとAtomics、String.padStart/padEnd、Object.values/entries、Object.getOwnPropertyDescriptors、関数の引数における末尾のカンマ許容
-
- 2018年
- ECMAScript 2018 (ECMA-262, 9th edition, June 2018) オブジェクトに対するスプレッド構文、非同期イテレーション、Promise.prototype.finally、正規表現への機能追加
-
- 2019年
- ECMAScript 2019 (ECMA-262, 10th edition, June 2019) Array.prototype.flat、Array.prototype.flatMap、Object.fromEntriesの追加、他
-
- 2020年
- ECMAScript 2020 (ECMA-262, 11th edition, June 2020) オプショナルチェイニング演算子、Null合体演算子、BigIntの追加、他
-
- 2021年
- ECMAScript 2021 (ECMA-262, 11th edition, June 2021) 出来ごと、出来ごと、出来ごと、出来ごと、出来ごと、出来ごと、出来ごと、出来ごと、出来ごと、出来ごと、出来ごと、出来ごと、出来ごと
-
- 2022年
- 出来事の見出し 出来ごと、出来ごと、出来ごと、出来ごと、出来ごと、出来ごと、出来ごと、出来ごと、出来ごと、出来ごと、出来ごと、出来ごと、出来ごと
このページについて
JavaScriptの概要
・Vanilla JSで記述
└→ jQuery不可なサイトが増えている
・クラス記述でモジュール化
├→ バンドルを容易にした
└→ 1ページ中に複数箇所設置可
・UL,LIタグ依存を解消し使い勝手向上
詳しくは、このページのリバース エンジニアリングを行って下さい。
__petit_chasedown.jsのソースコード
/*
* petit_chasedown(ぷちっ ちぇいすだうん)と呼称するものとする
*
* スクロールで縦線を描画
* 用途としてはタイムラインリスト(変遷)等に向いている
*
* ・ULタグとLIタグの組み合わせて用いる
* ・ULタグは複数でも可でCSSクラス名で指定(config中のchaseList)にて、CSSに下記を指定する
* max-width: 400px;
* width:100%;
* margin:50px auto;
* padding:0 30px;
* ・LIタグのCSSには下記の通り指定する
* position: relative;
* list-style: none;
* padding:0 0 20px 0; ※これはデザインに応じて
* ・LIタグ中にコンテンツブロックを書く
* position: relative;
* margin:0 0 20px 3em; ※左のパディングを下記の線引に重ならないようにする
* ・LIタグ中に線引用のブロックをクラス名で指定(config中のchaseLine)して、上記のコンテンツに重なるように配置
* position: absolute;
* left: 6px;
* top: 0;
* width: 3px;
* height:0;
* background: rgb(70,95,171);
* ・LIタグに●を表示する
* timeline li::after{
* content:'';
* position: absolute;
* top:0;
* left:0;
* width: 15px;
* height: 15px;
* background: rgb(70,95,171);
* border-radius: 50%;
*
* ・当該モジュールをimportしてインスタンス化するだけ
* ・class(Prototype糖衣構文)で複数属性の設定可
*
* SP Thx. 元ネタはこれです
* スクロールをするとタイムラインの縦線が伸びる
* https://coco-factory.jp/ugokuweb/move01/9-1-6/
* ※元ネタに改変してこと
* ・jQuery依存をなくしてモジュール化
* ・ULとLIタグの縛りを無してブロック要素ならOKに
*
* license: MIT
* author: booskanium
*
*/
export default class __Petit_chasedown {
//Tipsポップアップ欄の初期設定
constructor(cnf) {
this.config = {
chaseList: 'chaseList', // 追いかけ線表示するブロック全体
chaseItem: 'chaseItem', // 追いかけ線表示するアイテムブロック
chaseLine: 'chaseLine', // アイテムブロックに被せて追いかけ線表示するインラインブロック
startPoint: 150
}
// 独自設定を受け入れる設定
if (cnf) {
if ('chaseList' in cnf) this.config.chaseList = cnf.chaseList;
if ('chaseItem' in cnf) this.config.chaseItem = cnf.chaseItem;
if ('chaseLine' in cnf) this.config.chaseLine = cnf.chaseLine;
if ('startPoint' in cnf) this.config.startPoint = cnf.startPoint;
}
// 画面をスクロールをされた場合
window.addEventListener('scroll', () => {
this.drawLine_scrolling();
});
// ページが読み込まれたら
window.addEventListener('load', () => {
this.drawLine_scrolling();
});
}
//スクロール位置に応じて線引する
drawLine_scrolling() {
let CL = document.getElementsByClassName(this.config.chaseList);
CL = Array.from(CL); //HTMLCollectionを配列に変換
CL.forEach((cl) => {
let CI = cl.getElementsByClassName(this.config.chaseItem); //chaseList中のchaseItem要素の一覧
CI = Array.from(CI); //HTMLCollectionを配列に変換
CI.forEach((ci) => {
let windowHeight = window.innerHeight; // windowの高さ取得
let scroll = window.scrollY; // スクロール値取得
let elemPos = ci.offsetTop; // liのY軸オフセット
let startPoint = this.config.startPoint; // 線をスタートさせる位置を指定
if (scroll >= elemPos - windowHeight - startPoint){
//余白含めた高さ
let margin = this._getMargin(ci);
let H = ci.offsetHeight + margin.top + margin.bottom;
//スクロール値から要素までの高さを引いた値を、liの高さの半分のパーセント
let percent = (scroll + startPoint - elemPos) / (H/2) *100;
// 線引の長さが100% を超えたら100%
if(percent > 100){
percent = 100;
}
// 線引の長さがマイナス値だったら0%
if(percent < 0){
percent = 0;
}
// 線引を行う
let line = ci.getElementsByClassName(this.config.chaseLine);
line = Array.from(line);
line = line[0];
line.style.height = percent + "%";
}
});
});
}
//Marginを求める
_getMargin(elm) {
let styles = window.getComputedStyle(elm);
return {
top: parseFloat(styles.marginTop) || 0,
right: parseFloat(styles.marginRight) || 0,
bottom: parseFloat(styles.marginBottom) || 0,
left: parseFloat(styles.marginLeft) || 0,
}
}
}