summaryrefslogtreecommitdiff
path: root/index.js
blob: 57e378ecf517ee465769f257efa22aa577f3887f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const THRESHOLD_FIDELITY = 1000;

// mutation observer for the video element
const videoTitle = document.querySelector('#video-title');
console.log(videoTitle);

const pastryIframe = document.querySelector('#connie-pastries')
console.log(pastryIframe.textContent);


const observer = new IntersectionObserver(entries => {
    // note - if the boundingClientRect.y is negative, then they are scrolling down
    // note - since using id, only 1 entry
    const {intersectionRatio, boundingClientRect} = entries[0];
    if (intersectionRatio !== 1 && boundingClientRect.y <= 0) {
        videoTitle.currentTime = 5 - 2 * intersectionRatio;
    } else {
        videoTitle.currentTime = 2;
    }
}, {
    threshold: [...Array(THRESHOLD_FIDELITY).keys()].map(num => num/THRESHOLD_FIDELITY)
});

// after two seconds pause the video
setTimeout(() => {
    console.log('fired')
    videoTitle.pause();
    videoTitle.currentTime = 2;
    observer.observe(videoTitle);
}, 2500)

// math for interactive conic border on weekly specials
const conicElement = document.querySelector('.conic-border');
window.addEventListener('mousemove', ({ clientX, clientY }) => {
    const { x, y, width, height } = conicElement.getBoundingClientRect();
    const dx = clientX - (x + 0.5 * width);
    const dy = clientY - (y + 0.5 * height);
    const angle = Math.atan2(dy, dx) * 180 / Math.PI;

    conicElement.style.setProperty('--startDeg', `${angle + 90}deg`);
}, false);