Is it possible to dynamically alter the color of a span text over a specific period of time?

Within my span tag, I am displaying text dynamically over a specific duration by reading a webvtt file. However, I want to change the color of the text during this given duration.

I attempted to achieve this using CSS with transitions and passing the duration dynamically like so:

HTML Tag:

<span :data-text="lyric1" class="word" 
:style="'animation-duration:'+duration+'s'">{{ lyric }}
</span>

JavaScript Function:

showSubtitles(){
    for(let i = 0; i < this.subtitles.length; i++){
        if(this.songStart * 1000 >= this.subtitles[i].start
            && this.songStart * 1000 <= this.subtitles[i].end
        ){
            this.duration =(this.subtitles[i].end - this.subtitles[i].start) / 1000;
            this.lyric = this.lyric1 =  this.subtitles[i].part;
        }
    }
   this.lyricTimer =  setTimeout(function(){this.showSubtitles()}.bind(this), 500);
}

CSS:

.word::after {
  content: attr(data-text);
  position: absolute;
  left: 0;
  top: -10;
  color: #FFC61E;
  overflow: hidden;
  width: 0%;
  animation: run-text 10s infinite linear;
  animation-duration:inherit;
}

@keyframes run-text {
  from { width: 0 }
  to { width: 100% }
}

Although I provide the correct duration, the transitions do not finish within that time frame, often overlapping or not functioning as intended at all.

I suspect that this issue may stem from CSS struggling to keep up with such dynamic changes. Any suggestions on how to address this problem using native JavaScript or Vue framework would be greatly appreciated.

Answer №1

Styling subtitle cues in a WebVTT file is simple if you have access to the file. You can customize the text right within the WebVTT file by following the instructions provided in this resource:

Learn how to style WebVTT files from within

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Node.js ENOTFOUND error encountered while trying to utilize the Parse SDK for JavaScript

My goal is to retrieve a large amount of data from Parse, and I have implemented a recursive function as a solution. This function makes a request for data and then launches another request when the previous one is successful. The implementation is quite s ...

Looking at a 3D wireframe cube using three.js

I am a new three.js user and still learning Javascript. I successfully completed the "Getting Started" project on threejs.org, which consisted of a rotating cube, with no issues. However, when I attempted to add a wireframe to the project, it suddenly stop ...

Preventing grid-collection from iterating within a for loop in Liquid on Shopify

I am trying to find a solution to prevent the grid-collection div from iteratig inside a for loop. Below is a snippet of my code in liquid: {% for block in section.blocks %} {% if block.settings.download_title %} <div class="title& ...

Angular does not automatically add a class

My Angular function looks like this: $scope.show = function(el){ if($scope.steps[el] == true){ $scope.steps[el] = false; } else{ $scope.steps = []; $scope.steps[el] = true; } } When I trigger it by clicking on thi ...

Modify the CSS borders to reflect a selected radio input type

I'm attempting to change the color of a Radio Button to blue when it's selected, but I'm having trouble achieving this. Here is the CSS code I'm using: /* Radio Button Style */ .radio { padding-left: 25px; } .radio label { di ...

The error message "indexOf of undefined" appears when trying to read a property that does not exist within a new

Help Needed: The following error is happening: Cannot read property 'indexOf' of undefined at new HttpRequest (http.js:653) at HttpClient.request (http.js:1069) at HttpClient.get (http.js:1157) This occurs when I use the get() method from Ht ...

The TypeScript compiler is generating node_modules and type declaration files in opposition to the guidelines outlined in the tsconfig.json file

For the past week, I've been trying to troubleshoot this issue and it has me completely puzzled. What's even more puzzling is that this app was compiling perfectly fine for months until this problem occurred seemingly out of nowhere without any c ...

The value of msg.member is empty following the messageReactionAdd event

Whenever someone reacts on my server, it triggers the messageReactionAdd event. However, I am encountering difficulty in retrieving the member object of the author of a message that someone reacted to: module.exports = async (client, messageReaction, user) ...

Adding a conditional to target a bootstrap modal in AngularJS

I am facing a situation where I need a modal to only appear when specific conditions defined in my controller are met, rather than every time a button is clicked. Here's the HTML CODE: <button class="btn btn-primary-outline" type="button" data-uk ...

The significance of the "$=" or "?=" symbols in lit-element illustrations

I'm struggling to comprehend the purpose of ?= or $= in these two instances: First Example: Lit-Element README <div id="box" class$="${this.uppercase ? 'uppercase' : ''}"> <slot>Hello World</slot> </div> ...

HTML and CSS for an off-canvas menu

Looking to create an off-canvas menu that smoothly pushes content out of view instead of cropping it. Additionally, I want to implement a feature that allows the menu to close when clicking outside of it. I found the code for the off-canvas menu on W3Scho ...

Hover over the drop-down menu to enable tab on hover mode

Is it possible to make the tab switch to hover mode when I rollover the drop down sub-menu without using JavaScript, and only using CSS? <li id="anchor" class="title dropdown"><a href="#">Main Tab</a> <div class="co ...

Update destination upon click

I'm new to JavaScript and attempting to modify a redirect link using checkboxes that will modify the URL, followed by a button that will use the updated URL. However, I'm facing some challenges with my code and could use some guidance. Here is t ...

How can I include additional lines in a 3D model?

https://i.sstatic.net/NH1sB.png In my latest project using three.js, I created a 3D human model and now I want to enhance it by adding angle lines similar to the red ones I manually drew on the image. Does anyone know how to achieve this effect? ...

Having trouble implementing uppercase text in Bootstrap editable modules

Recently, I implemented the bootstrap editable function in my application and it was functioning perfectly. However, I am now looking to have the editable text always display in uppercase format. Unfortunately, I am unsure of how to achieve this. Any sugge ...

Is the "mocha" command line tool requires quotation marks for specifying test files?

Here are some examples of npm scripts: "scripts": { "test": "mocha tools/testSetup.js src/**/*.spec.js" } "scripts": { "test": "mocha tools/testSetup.js 'src/**/*.spec.js'" } "scripts": { "test": "mocha tools/testSetup.js \"src/**/* ...

Implementing Bootstrap 3.1 to prioritize main content at the top on mobile devices

Below is the grid structure that I am working with <div class="row"> <div id="A" class="col-md-3"> <div class="alert alert-info">A</div> </div> <div id="B" class="col-md-6"> <div class=" ...

Steps for updating information in Firebase version 9

How can I add a new record and also change the 'bill' value, but I'm not sure what to input in this string? const newPostKey = (child(ref(db), )).key; This is the Vuex action I am using to make a request to Firebase: async updateInfo({ disp ...

Finding the maximum value among multiple variables in AngularJS

After performing calculations, I have assigned specific values to variables. console.log("Gain_weight is "+ Gain_weight); console.log("Gain_smoking is "+ Gain_smoking); console.log("Gain_exercising is "+ Gain_exercising); console.log("Gain_foodhabits ...

Tips for capturing changes in a "count" variable and executing actions based on its value

I have a counter on my webpage and I'm trying to change the style of an element based on the count variable. I tried using the .change action but I haven't been able to get it working. It might not be the right solution. Can anyone provide some ...