繼續挑戰,這週希望能自己有些想法,可以邊做邊去挑戰。
// Get elements
const player = document.querySelector('.player');
const video = player.querySelector('.viewer');
const progress = player.querySelector('.progress');
const progressBar = player.querySelector('.progress__filled');
const toggle = player.querySelector('.toggle');
const skipButton =player.querySelectorAll('[data-skip]')
const ranges = player.querySelectorAll('.player__slider')
// function
function togglePlay(){
if(video.paused){video.play()}
else {video.pause()}
}
function updateButton(){
const icon = this.paused ? '►' : '❚ ❚';
toggle.textContent = icon ;
}
//no playing property , only paused
function skip(){
console.log(this.dataset.skip);
video.currentTime += parseFloat(this.dataset.skip);
}
function handleRangeUpdate(){
video[this.name] = this.value;
}
function handleProgess(){
const percent = (video.currentTime / video.duration) * 100 ;
progressBar.style.flexBasis = `${percent}%` ;
}
function scrub(e){
const scrubTime = (e.offsetX / progress.offsetWidth) * video.duration;
video.currentTime = scrubTime;
}
// Hook up event listener
video.addEventListener('click', togglePlay);
video.addEventListener('play', updateButton);
video.addEventListener('pause',updateButton);
video.addEventListener('timeupdate',handleProgess);
toggle.addEventListener('click', togglePlay);
skipButton.forEach(button => button.addEventListener('click', skip));
ranges.forEach(range => range.addEventListener('change', handleRangeUpdate));
ranges.forEach(range => range.addEventListener('mousemove', handleRangeUpdate));
let mousedown = false ;
progress.addEventListener('click', scrub);
progress.addEventListener('mousemove', (e) => mousedown && scrub(e));
progress.addEventListener('mousedown' ,() => mousedown = true);
progress.addEventListener('mouseup' ,() => mousedown = false);
cornify.js
const pressed = [] ;
const secretCode = 'frank';
window.addEventListener('keyup', (e) => {
pressed.push(e.key);
pressed.splice(-secretCode.length-1 ,pressed.length - secretCode.length);
console.log(pressed);
if (pressed.join('').includes(secretCode)) {
console.log('!!!YAYAYA!!!');
cornify_add(); /// cornify.js的效果
}
})