Skip to content

Commit

Permalink
span the names closer to the center
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdaniculae committed Apr 11, 2024
1 parent 25322a7 commit ac0d7c2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Experience/Extras/Congrats.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,19 @@ export default class Congrats {
}
const centralRect = centralElement.getBoundingClientRect()

const marginWidth = window.innerWidth * 0.2 // 20% of viewport width
const marginHeight = window.innerHeight * 0.2 // 20% of viewport height

names.forEach((name) => {
let randomX, randomY, overlap

do {
overlap = false
randomX = Math.random() * (window.innerWidth - name.offsetWidth)
randomY = Math.random() * (window.innerHeight - name.offsetHeight)
// Adjust calculations to consider margins
randomX = marginWidth + Math.random() * (window.innerWidth - 2 * marginWidth - name.offsetWidth)
randomY = marginHeight + Math.random() * (window.innerHeight - 2 * marginHeight - name.offsetHeight)

// Check if the random position overlaps with the central element
overlap = randomX < centralRect.right && randomX + name.offsetWidth > centralRect.left && randomY < centralRect.bottom && randomY + name.offsetHeight > centralRect.top
} while (overlap)

Expand Down

0 comments on commit ac0d7c2

Please sign in to comment.