Skip to content

Commit

Permalink
Animated emojis only animated on hover on the web interface
Browse files Browse the repository at this point in the history
By default GoToSocial will display animated emojis on the web interface.

Since v0.17.0, GoToSocial has made it to respect when you have `prefers-reduced-motion` setting enabled on your system.

What my change does is duplicate the emoji img tag, one with the classname `.emoji.original` and one with the classname `.emoji.static`, with the static version's `src` being set to `staticURL` like for the prefers reduced motion version.

In order for this to work, you need to add to CSS somewhere such as your custom CSS or in web assets (or the global custom CSS when that is implemented:

```
.emoji.original { display: none; }
picture:hover .emoji.static { display: none }
picture:hover .emoji.original { display: inline-block }
```

This will hide the static emoji when you hover/tap and show the original emoji instead so it'll animate on hover when it's an animated emoji.

This isn't a perfect solution, that it needs to load the original version when you hover, but it is a very minimal and JS free solution.

This still respects the `prefers-reduced-motion` set by the system, whilst also offering Mastodon web interface default behaviour by animated emojis only animating on hover/tap, so a flashing/fast paced emoji present in a thread isn't going to cause discomfort when viewing said thread on the web interface.
  • Loading branch information
jwbjnwolf committed Sep 25, 2024
1 parent 27ba6ff commit 5a9095d
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions internal/text/emojify.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func EmojifyWeb(emojis []apimodel.Emoji, html template.HTML) template.HTML {
// Original image source.
buf.WriteString(`<img `)
{
buf.WriteString(`class="emoji" `)
buf.WriteString(`class="emoji original" `)
buf.WriteString(`src="` + url + `" `)
buf.WriteString(`title=":` + code + `:" `)
buf.WriteString(`alt=":` + code + `:" `)
Expand All @@ -68,6 +68,22 @@ func EmojifyWeb(emojis []apimodel.Emoji, html template.HTML) template.HTML {
}
buf.WriteString(`/>`)

// Static version globally.
buf.WriteString(`<img `)
{
buf.WriteString(`class="emoji static" `)
buf.WriteString(`src="` + staticURL + `" `)
buf.WriteString(`title=":` + code + `:" `)
buf.WriteString(`alt=":` + code + `:" `)
// Lazy load emojis when
// they scroll into view.
buf.WriteString(`loading="lazy" `)
// Limit size to avoid showing
// huge emojis when unstyled.
buf.WriteString(`width="25" height="25" `)
}
buf.WriteString(`/>`)

// Close the picture tag.
buf.WriteString(`</picture>`)
},
Expand Down Expand Up @@ -140,4 +156,4 @@ func emojify(
return buf.String()
},
)
}
}

0 comments on commit 5a9095d

Please sign in to comment.