-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f88440a
commit 0235ab8
Showing
12 changed files
with
102 additions
and
24 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
title: CSS Event Listeners - Sparks | ||
published_at: 2024-02-20 | ||
updated_at: 2024-02-20 | ||
--- | ||
|
||
|
||
## TLDR | ||
|
||
Using CSS resources loading behavior to observe user interactions. | ||
|
||
<br> | ||
|
||
## Concept | ||
|
||
CSS properties that specify some resource like a background | ||
image are requested only when their css block is active. | ||
|
||
```css | ||
/* The image is only requested when you hover over the element */ | ||
|
||
.Element:hover { | ||
background-image : url('/Asset/Image.png') ; | ||
} | ||
``` | ||
|
||
Of course we don't actually need to use a real image, instead we can | ||
specify a custom endpoint that only returns a success status code. | ||
|
||
```css | ||
.Element:hover { | ||
background-image : url('/API/OnHover') ; | ||
} | ||
``` | ||
|
||
*Now we know when someone hovers over the element.* | ||
|
||
<br> | ||
|
||
## Cache Busting | ||
|
||
This method however only works once, the second time | ||
you hover of the element, the request won't be send again. | ||
|
||
The most reliable method to counteract this is to make the url | ||
unique on every hover via either a different path or parameter. | ||
|
||
```css | ||
/* Uses the response timestamp as uniqueness factor */ | ||
|
||
.Element:hover { | ||
background-image : url('/API/OnHover/1708403536337') | ||
} | ||
``` | ||
|
||
<br> | ||
|
||
## Complementary Events | ||
|
||
With our current setup we are actually spamming our server with | ||
requests as when you hover the element, new rule with a unique | ||
path is added and active right away, prompting another request. | ||
|
||
To stop this cyclic hell and to get more use out of the | ||
technique we should consider the complementary event, | ||
in this case the user stopping to hover over the element. | ||
|
||
|
||
|
||
<!-----------------------------------------------------------------------------> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
@tailwind utilities; | ||
|
||
@layer base { | ||
.font-outline { | ||
-webkit-text-stroke: 3px white; | ||
}.font-outline-2 { | ||
-webkit-text-stroke: 1.2px white; | ||
} | ||
} | ||
|
||
|
||
.Header { | ||
inset-inline : 0 ; | ||
justify-content : center ; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters