homepage/_assets/js/lens.js

88 lines
2 KiB
JavaScript
Raw Permalink Normal View History

2023-03-15 09:07:15 +00:00
// OK so the next thing to do is make it so it's blurry when the screen is too
// big or too small, and thne prompt someone to make their screen bigger or smaller
// to be a lens and then you have to move the window around to be able to see the different
// links on the page
2023-03-15 09:04:46 +00:00
2023-03-15 18:40:37 +00:00
const FOCUS_SIZE = 400;
2023-03-15 09:04:46 +00:00
function _init(){
2023-03-15 18:40:37 +00:00
let root = document.querySelector(':root');
let lens = document.getElementsByClassName('lens')[0];
let filter = document.getElementById('filter');
let hid_hint = false;
2023-03-15 09:04:46 +00:00
if (!lens){
console.log('not doing lens')
return
}
2023-03-15 18:40:37 +00:00
// let FOCUS_SIZE = root.style.getPropertyValue('--lens-size')
root.style.setProperty(
2023-03-15 09:04:46 +00:00
'--screen-width',
`${window.screen.availWidth}px`
);
2023-03-15 18:40:37 +00:00
root.style.setProperty(
2023-03-15 09:04:46 +00:00
'--screen-height',
`${window.screen.availHeight}px`
);
function set_position(){
lens.style.transform = `translate(-${window.screenX}px, -${window.screenY}px)`
setTimeout(set_position, 10);
}
2023-03-15 18:40:37 +00:00
function get_blur(){
return Math.max(
Math.sqrt(
(
Math.abs(window.innerHeight-FOCUS_SIZE) +
Math.abs(window.innerWidth-FOCUS_SIZE)
) / 4)-5,
0)
}
function set_blur(){
let blur_radius = get_blur()
filter.style.setProperty(
'--blur-radius',
`${blur_radius}px`
)
setTimeout(set_blur, 50);
}
function show_hint(){
if (get_blur() > 3) {
let hint = document.getElementById('hint');
hint.classList.remove('hidden')
setTimeout(check_hint, 2000);
}
}
function check_hint(){
if (get_blur() < 3){
let hint = document.getElementById('hint');
hint.classList.add('rehidden');
hid_hint = true;
}
if (hid_hint === false){
setTimeout(check_hint, 100);
}
}
2023-03-15 09:04:46 +00:00
set_position();
2023-03-15 18:40:37 +00:00
set_blur();
setTimeout(show_hint, 2000);
2023-03-15 09:04:46 +00:00
// setTimeout(set_size,100);
// set_size()
}
export function init(){
// document.addEventListener('load', () => {
// _init();
// })
_init();
}