Mattias Bodlund 6 months ago
parent
commit
57a62e4b78
2 changed files with 13 additions and 18 deletions
  1. +12
    -17
      app/javascript/application.js
  2. +1
    -1
      app/views/questions/result.html.erb

+ 12
- 17
app/javascript/application.js View File

@ -169,26 +169,25 @@ function animateElementsSequentially(index = 0) {
const highestBar = sortedPercentages[0]
const lowestBar = sortedPercentages[sortedPercentages.length - 1]
let equalHeight = answerDistributions[0].offsetHeight
let equalHeight = answerDistributions[0].offsetHeight
answerDistributions.forEach((bar, i) => {
let fakeHeight, finalHeight
if (i === highestBar.index) {
fakeHeight = containerHeight * 0.3
fakeHeight = containerHeight * (0.3 + ((Math.random() - 0.5) * 0.2))
} else if (i === lowestBar.index) {
fakeHeight = containerHeight * 0.8
fakeHeight = containerHeight * (0.8 + ((Math.random() - 0.5) * 0.2))
} else {
fakeHeight = containerHeight * 0.5
fakeHeight = containerHeight * (0.5 + ((Math.random() - 0.5) * 0.2))
}
finalHeight = targetHeights[i]
gsap.to(bar, {
keyframes: [
{ height: fakeHeight, duration: 0.4, ease: "power2.out" },
{ height: equalHeight, duration: 0.4, ease: "power2.inOut" },
{ height: finalHeight, duration: 0.4, ease: "power2.out" }
{ height: fakeHeight, duration: 0.3, ease: "power2.inOut" },
{ height: finalHeight, duration: 0.4, ease: "power2.in" }
],
onComplete: () => {
if (bar.dataset.answered != undefined) {
@ -212,15 +211,10 @@ function animateElementsSequentially(index = 0) {
}
})
})
return
}
animateElementsSequentially(index + 1)
animateElementsSequentially(index + 1)
}
})
}
@ -234,8 +228,8 @@ function animateElementsSequentially(index = 0) {
function typeWriterConsoleSequential(container, options = {}) {
const {
selector = '.typewriter-text',
baseSpeed = 60,
divDelay = 400,
baseSpeed = 40,
divDelay = 200,
showCursor = true,
onDivComplete = null,
onAllComplete = null
@ -344,7 +338,7 @@ function typeWriterConsoleSequential(container, options = {}) {
let charIndex = 0
// Add 1 second delay for first div to let cursor blink twice
let nextCharTime = performance.now() + (isFirstDiv ? 1100 : 100)
let nextCharTime = performance.now() + (isFirstDiv ? 20 : 20)
function typeFrame(currentTime) {
if (!isActive) {
@ -361,7 +355,8 @@ function typeWriterConsoleSequential(container, options = {}) {
updateDivContent(currentDiv, currentText, true)
// Calculate delay for next character
let delay = baseSpeed + Math.random() * 15
// let delay = baseSpeed + Math.random() * 15
let delay = baseSpeed
const char = originalText.charAt(charIndex - 1)
if (char === '.' || char === '!' || char === '?') {


+ 1
- 1
app/views/questions/result.html.erb View File

@ -26,7 +26,7 @@
<div class="animation-element">
<div class="result-actions">
<%= link_to tag.span(t('read_more')), t('read_more_link'), class: 'button__base' %>
<%= link_to tag.span(t('read_more')), t('read_more_link'), class: 'button__base', target: '_blank' %>
<%= button_tag tag.span(t('share_on_story')),
data: {
share_title: t('share.title'),


Loading…
Cancel
Save