Skip to content

Commit

Permalink
Started CSS Sparks
Browse files Browse the repository at this point in the history
  • Loading branch information
PhoneDroid committed Feb 20, 2024
1 parent f88440a commit 0235ab8
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 24 deletions.
8 changes: 8 additions & 0 deletions assets/CSS Sparks.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { site } from "../data/site.ts";

export function Header() {
return (
<header class="px-3 py-3 bg-yellow-200 h-16 flex items-center">
<header class="px-3 py-3 bg-[#84ea9a] h-16 flex items-center">
<div class="px-4 max-w-screen-md">
<a href="/" class="text-2xl font-bold hover:text-underline">
{site.title}
<span class = 'text-[#ffdc17] font-outline-2'>JS</span>
<span class = 'text-[#e04d6e] font-outline-2'>Less</span>
</a>
</div>
</header>
Expand Down
7 changes: 4 additions & 3 deletions components/HomeHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { site } from "../data/site.ts";
export function HomeHeader() {
return (
<header
class="bg-yellow-200 relative min-h-[30vh]"
class="bg-[#84ea9a] relative min-h-[30vh]"
>
<Container>
<h1 class="text-4xl lg:text-8xl font-bold absolute bottom-6 flex items-center">
{site.title}
<h1 class="Header text-4xl lg:text-8xl font-bold absolute bottom-6 flex items-center">
<span class = 'text-[#ffdc17] font-outline'>JS</span>
<span class = 'text-[#e04d6e] font-outline'>Less</span>
</h1>
</Container>
</header>
Expand Down
70 changes: 70 additions & 0 deletions data/posts/CSS-Event-Listeners-Sparks.md
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.



<!----------------------------------------------------------------------------->
9 changes: 0 additions & 9 deletions data/posts/create-a-deno-deploy-button.md

This file was deleted.

1 change: 0 additions & 1 deletion data/site.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export const site = {
title: 'JSLess Blog',
description: 'Interactivity without JavaScript',
// This should be a url to the static file you're using for your open graph image
ogImage: 'https://fresh-blog.littlesticks.dev/og-image.png',
Expand Down
2 changes: 1 addition & 1 deletion routes/blog/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function PostPage(props: PageProps<Data>) {
</time>
</span>

{ ( post.updatedAt !== post.publishedAt ) && <>
{ ( post.updatedAt.getMilliseconds() !== post.publishedAt.getMilliseconds() ) && <>

<span>
<b>Updated : </b>
Expand Down
Binary file modified static/favicon.ico
Binary file not shown.
6 changes: 0 additions & 6 deletions static/logo.svg

This file was deleted.

Binary file removed static/og-image.png
Binary file not shown.
16 changes: 15 additions & 1 deletion static/styles.css
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 ;
}
2 changes: 1 addition & 1 deletion tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {
setup: {
theme: {
colors: {
yellow: colors.yellow,
yellow: '#84ea9a',
transparent: 'transparent',
},
},
Expand Down

0 comments on commit 0235ab8

Please sign in to comment.