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.
.container#app
p.lead
| delayが32bitを超えているとすぐ実行されてしまう。
.card-deck
.card(v-for="item in items")
.card-header
| {{ item.support }}
br
small.text-muted
span.mr-1 delay:
| {{ item.delay | separate }}
.card-body
h4.card-title(v-show="item.rest > 0")
small.mr-2 あと
| {{ item.rest | formatMsec | separate }}
small.ml-1 秒
h4.card-title(v-show="item.rest <= 0")
| 完了
p.card-text
| {{ item.delay | formatTimestamp(startAt, "YYYY/M/D") }}
| {{ item.delay | formatTimestamp(startAt, "HH:mm:ss") }}
p.card-text
| timeout:
span(v-show="item.isTimeoutDone", v-bind:class="{ 'badge-success': item.rest <= 0, 'badge-danger': item.rest > 0 }").ml-1.badge.badge-pill
| Complete
span(v-show="!item.isTimeoutDone").ml-1.badge.badge-pill.badge-secondary
| Progress
body {
margin: 20px;
}
.text-white {
.text-muted {
color: rgba(#fff, .8) !important;
}
}
const value = {
startAt: 0, // 計測開始日時
progressTime: 0, // 経過ミリ秒
items: [
{
delay: 5 * 1000, // 5秒
rest: 0,
isTimeoutDone: false,
support: '5秒'
},
{
delay: 60 * 1000, // 1分
rest: 0,
isTimeoutDone: false,
support: '1分'
},
{
delay: 2147483647, // 32bit上限
rest: 0,
isTimeoutDone: false,
support: '32ビットの最大値'
},
{
delay: 2147483648, // 32bit超える
rest: 0,
isTimeoutDone: false,
support: '32ビットを超える値'
}
]
};
const app = new Vue({
el: '#app',
data: value,
mounted: function() {
// 計測開始
this.startAt = new Date().getTime();
this.progress();
setInterval(() => {
this.progress();
}, 1000);
// setTimeoutを設定する
this.items.forEach(function (value, index) {
setTimeout(function () {
value.isTimeoutDone = true;
}, value.delay);
});
},
methods: {
progress: function() {
const progressTime = new Date().getTime() - this.startAt;
this.progressTime = progressTime;
// 計算し直す
this.items.forEach(function (value, index) {
value.rest = Math.max(value.delay - progressTime, 0); // 0を下回らないように
});
}
},
filters: {
/**
* 3桁ごとにカンマ
*
* @param num {number} 数値
* @return {string} 3桁区切り
*/
separate: function (num) {
return String(num).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,');
},
/**
* ミリ秒をフォーマットする
*
* @param msec {number} ミリ秒
* @return {number} フォーマットした秒
*/
formatMsec: function(msec) {
// 小数点を省略
return Math.round(msec / 1000);
},
/**
* タイムスタンプをフォーマットする
*
* @param timestamp {number} タイムスタンプ
* @param startAt {number} 基準時間
* @param format {string} フォーマット
* @return {string} フォーマットしたタイムスタンプ
*/
formatTimestamp: function (timestamp, startAt, format = '') {
return moment(startAt, 'x').add(timestamp, 'ms').format(format);
}
}
});
Also see: Tab Triggers