-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.js
More file actions
55 lines (46 loc) · 1.35 KB
/
example.js
File metadata and controls
55 lines (46 loc) · 1.35 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
import Keyframes from '@keyframes/core';
import Proximity from '../src/keyframes.proximity';
Keyframes.plugin(Proximity);
const $ = selector => document.querySelectorAll(selector)[0];
const blockElem = $('.block');
const bc2 = $('.block-container.bc2').getBoundingClientRect();
const block = new Keyframes(blockElem);
const topPosition = {
top: '20px',
};
Keyframes.define([{
name: 'initiate',
'0%': {
top: '-100px',
},
'100%': topPosition,
}, {
name: 'makeTheMove',
'0%': topPosition,
'100%': {
top: `${bc2.top - 20}px`,
},
}]);
window.onload = function () {
let readyToProximity = false;
let isMoving = false;
let directionSwitch = true;
block.play('initiate 1s ease 0s 1 normal forwards', () => {
readyToProximity = true;
});
block.proximity((obj) => {
if (readyToProximity) {
blockElem.style.boxShadow = `red 0 0 ${0.5 * obj.distancePercentage}px`;
}
});
blockElem.addEventListener('mouseover', (e) => {
if (!isMoving) {
isMoving = true;
const direction = directionSwitch ? 'normal' : 'reverse';
directionSwitch = !directionSwitch;
block.reset(() => block.play(`makeTheMove 2s ease 0s 1 ${direction} forwards`, () => {
isMoving = false;
}));
}
});
};