Skip to content

Commit 5a28ab0

Browse files
committed
background mouse shadow
1 parent f589430 commit 5a28ab0

File tree

6 files changed

+77
-1
lines changed

6 files changed

+77
-1
lines changed

blocks/cursor/cursor--temp.cur

-2.4 KB
Binary file not shown.

blocks/cursor/cursor--temp.png

-1 KB
Binary file not shown.

blocks/cursor/cursor.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
:root,
33
html,
44
body {
5-
cursor: url(cursor--temp.cur) 12 12, auto;
5+
cursor: none;
66
}

blocks/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import './card/card.js';
22
import './button/button.js';
3+
import './page/Page.js';
34
import projects from './projects/projects.js';
45
import projectCard from './project-card/project-card.js';
56
import tags from './tags/tags.js';

blocks/page/Page.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import MC from '../../js/mouseShadow/MouseShadowController.js';
2+
3+
/**
4+
* Base for the mouse shadow controller for button blocks, which automates
5+
* the mouse shadow effect
6+
* @abstract
7+
* @extends MouseShadowController
8+
*/
9+
class Page extends MC {
10+
/**
11+
* @param {String} [modifier = ''] Modifier of the button block.
12+
* Default '' means mo modifier.
13+
* @returns {void}
14+
*/
15+
constructor() {
16+
super(document.getElementsByTagName('html')[0], ['page'], '.page');
17+
}
18+
19+
/**
20+
* more specific version of {MouseShadowController}'s
21+
* mousemoveEventShadow that already specifies where to find the
22+
* passed shadow functions and what elements it applies to
23+
* @see MouseShadowController
24+
* @returns {void}
25+
*/
26+
mousemoveEventShadow() {
27+
super.mousemoveEventShadow(
28+
this._shadowFunction,
29+
'*',
30+
this._postShadowFunction
31+
);
32+
}
33+
34+
/**
35+
* function which takes an object args which contains e mousemove
36+
* event (event) and returns css changes
37+
* @param {object} args
38+
* @returns {object} object of css properties and their values
39+
*/
40+
_shadowFunction(args) {
41+
const
42+
rect = args.eventControlElement.domElement.getBoundingClientRect(),
43+
hover = [
44+
args.event.clientX - rect.left,
45+
args.event.clientY - rect.top
46+
];
47+
48+
return {
49+
'--page--mouse-shadow-left': hover[0],
50+
'--page--mouse-shadow-top': hover[1],
51+
'--page--center': Math.max(
52+
Math.abs(args.event.clientX - 0.5 * rect.width),
53+
Math.abs(args.event.clientY - 0.5 * rect.height)),
54+
'--page--center-v': Math.abs(args.event.clientY - 0.5 * rect.height)
55+
};
56+
}
57+
58+
_postShadowFunction() {
59+
60+
}
61+
}
62+
63+
new Page().mousemoveEventShadow();

blocks/page/page.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ html,
4444
--_h: var(--h, calc(var(--_w) * 0.618033988));
4545

4646
background-color: var(--c0);
47+
background-image:
48+
radial-gradient(
49+
circle at
50+
calc(
51+
var(--page--mouse-shadow-left, -10000) * 1px
52+
)
53+
calc(
54+
var(--page--mouse-shadow-top, -10000) * 1px
55+
),
56+
var(--c1) 0,
57+
var(--c0) calc(var(--page--center) * 0.05vw)
58+
);
4759
color: var(--c1);
4860
font-family: "Manrope", Arial, Verdana, Tahoma, sans-serif;
4961
height: 100vh;

0 commit comments

Comments
 (0)