Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions assets/javascripts/new-javascripts/hero.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const heroAnimation = async () => {
const reduceMotion = document.body.classList.contains('reduced-motion')
const isReduceMotionEnabled = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
const urlParams = new URLSearchParams(location.search)
const hasDebugParam = urlParams.has('debug')

Expand Down Expand Up @@ -103,23 +103,35 @@ const heroAnimation = async () => {
// Convert SVG path pulled from AE masks
let pathInstance = new Path2D(path)

ctx.setLineDash([pathLength])
ctx.lineDashOffset = pathLength
if (!isReduceMotionEnabled) {
ctx.setLineDash([pathLength])
ctx.lineDashOffset = pathLength

if (hasDebugParam) {
ctx.strokeStyle = debugColor
ctx.stroke(pathInstance)
if (hasDebugParam) {
ctx.strokeStyle = debugColor
ctx.stroke(pathInstance)
}
} else {
ctx.drawImage(image, 0, 0)
}

return { ctx, pathInstance }
}

const initLogo = ({ canvas, image, positionStart: [posX, posY] }) => {
const initLogo = ({ canvas, image, positionStart: [posX, posY], positionEnd: [endX, endY] }) => {
const ctx = canvas.getContext('2d')
ctx.globalAlpha = 0
// Same reason for conversion as initSwoops
ctx.translate(posX - image.naturalWidth / 2, posY - image.naturalHeight / 2)

ctx.drawImage(image, 0, 0)
if (!isReduceMotionEnabled) {
ctx.globalAlpha = 0
ctx.drawImage(image, 0, 0)
} else {
ctx.globalAlpha = 1
const deltaX = endX - posX;
const deltaY = endY - posY;
ctx.drawImage(image, deltaX, deltaY);
}

return ctx
}
Expand All @@ -135,18 +147,22 @@ const heroAnimation = async () => {
logo.image = logoImage
// init canvas for each swoop layer
heroSwoops.forEach((swoop, i) => {
swoop.image = swoopImages[i]
const canvasData = initSwoops(swoop)
swoop.ctx = canvasData.ctx
swoop.pathInstance = canvasData.pathInstance
})
swoop.image = swoopImages[i];
Copy link
Contributor

@jesseaborden jesseaborden May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like formatter missed the ";"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am planning to make a PR to run the formatter later. I didn't want to run it because it is going to affect other files outside this PR

const canvasData = initSwoops(swoop);
swoop.ctx = canvasData.ctx;
swoop.pathInstance = canvasData.pathInstance;
});
// init logo canvas
logo.ctx = initLogo(logo)
} catch (error) {
console.error('Error loading images:', error)
throw error
}

if (isReduceMotionEnabled) {
return;
}

const DURATION = 1000

const tl = anime.createTimeline({
Expand Down