ways to halt a noise once an animation is complete

I don't have much experience with coding in general, but somehow I've made it this far. Now I'm stuck on the final piece of the puzzle.

This is related to a Twitch alert that I'm setting up through 'Stream Elements'.

The issue I'm facing is how to stop the sound once all the typing letters have fully appeared. I'm completely lost on how to achieve this. Is it even possible?

Forgot to mention, the Typekit links are purposely broken as I didn't want to share the specific link (I assume they're unique and tied to your Adobe account).

$(document).ready(function() {
    var timer, fullText, currentOffset, onComplete,  hearbeat = document.getElementById('heartbeat');

    heartbeat.play();
    function Speak(person, text, callback) {
        $("#usernamean-container").html(person);
        fullText = text;
        currentOffset = 0;
        onComplete = callback;
        timer = setInterval(onTick, 120
       );
    }

    function onTick() {
        currentOffset++;
        if (currentOffset == fullText.length) {
            complete();
            return;
        }
        var text = fullText.substring(0, currentOffset);
        $("#message").html(text);
    }
    function complete() {
        clearInterval(timer);
        timer = null;
        $("#message").html(fullText);
        onComplete()
        ;
    }

    $(".box").click(function () {
        complete();
    });

    Speak("{{name}}",
        "{{name}} Is now a Witness",
    )
    //get data from the 🤟 StreamElements 🤟 data injection
    const name = '{{name}}';

    // vanilla es6 query selection (can use libraries and frameworks too)
    const userNameContainer = document.querySelector('#username-container');

    // change the inner html to animate it 🤪
    userNameContainer.innerHTML = stringToAnimatedHTML(name, animation);

    /**
     * return an html, with animation
     * @param s: the text
     * @param anim: the animation to use on the text
     * @returns {string}
     */
    function stringToAnimatedHTML(s, anim) {
        let stringAsArray = s.split('');
        stringAsArray = stringAsArray.map((letter) => {
            return `<span class="animated-letter ${anim}">${letter}</span>`
        });
        return stringAsArray.join('');

    }
    heartbeat.pause();
    heartbeat.currentTime = 0;
});
@import url(@import url("https://use.typekit.net/.css");

.awsome-text-container {
    font-family: typeka, sans-serif;
    font-size: 42px;
    font-weight: 400;
}

.image-container {
    margin: auto;
    display: table;
}

.text-container {
    font-family: typeka, sans-serif;
    font-size: 26px;
    color: rgb(204, 10, 33);
    text-align: center;
    margin: auto;
    text-shadow: rgba(0, 0, 0, 0.5) 1px 1px 1px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="heart" class="heart">
    <audio id="heartbeat" src="https://cdn.discordapp.com/attachments/135995830279733248/733547597305741332/typewriters.mp3" preload="auto"></audio>
  <link rel="stylesheet" href="https://use.typekit.net/.css">
  <div class="text-container">
      <div class="image-container">
          <img src="https://media.tenor.com/images/83d6a5ed40a24164dfe1e4e19fad23d9/tenor.gif">
      </div>
      <div>
          <div class="awsome-text-container">
              <span id="message"></span>
              <br>
          </div>
      </div>
</div>

Answer â„–1

Greetings and salutations on your arrival to Stack Overflow!

I have observed more chaotic code in the past, which left me underwhelmed ;-). In regards to your inquiry:

The main issue seems to be a simple typo within your code where you are invoking heartbeat.pause(); inside the complete method instead of at the end of the script (which should be executed regardless of the animation's completion).

Error:

hearbeat = document.getElementById('heartbeat');

Revised method:

function complete() {
    clearInterval(timer);
    timer = null;
    $("#message").html(fullText);
    heartbeat.pause();
    heartbeat.currentTime = 0;
}

Also, remember to eliminate the lines from the bottom of your script.

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

AngularJS: Identifying the position (ON/OFF) of ui-switch

I'm having trouble figuring out how to identify the position of my UI switch (true/false) in my JavaScript file. Here is my HTML file with the UI switch: <ui-switch ng-model='onOff'></ui-switch> And here is my controller for t ...

The life cycle of the request/response object in Express.js when using callbacks

Feel free to correct me if this question has already been asked. (I've done as much research as I can handle before asking) I'm really trying to wrap my head around the life cycle of request and response objects. Take a look at the following co ...

Exploring the concept of reflection in JavaScript and jQuery

Here is a javascript object I have: person.Name = "John"; person.Nick = "Smith"; person.Info = "hi there"; In addition, I have some HTML elements as shown below: <input id="Name" /> <input id="Nick" /> <input id="Info" /> My question ...

Troublesome alignment with bootstrap grid system

I require some assistance with the following: Specifically, I need help regarding the structure shown below: <div class="row"><div class="col-md-4"> <a class="individ" href="index.php?p=x" style="margin:5px 5px;"> ...

Tips on utilizing ajax to load context without needing to refresh the entire page

As a beginner in AJAX, I have some understanding of it. However, I am facing an issue on how to refresh the page when a new order (order_id, order_date, and order_time) is placed. I came across some code on YouTube that I tried implementing, but I'm n ...

Implementing AngularJS JQuery Datatables Directive for Displaying Multiple Data Tables within a Single View

I have successfully implemented the following directive: angular.module('myApp').directive('jqdatatable', function () { return { restrict: 'A', link: function (scope, element, attrs, ngModelCtrl) { ...

Creating a unique navigation route in React

My application has a consistent layout for all routes except one, which will be completely different from the rest. The entire application will include a menu, body, footer, etc. However, the one-off route should be standalone without these elements. How ...

Trouble with executing AJAX for API call

My current project is built on CI3 and I have created an API that belongs to a different domain than the application itself. $.ajax({ url: "http://www.example.com/restapi/index.php/api/user", type: "GET", data: {"user_id": user_id} ...

Discovered an issue with Sentry debugging where a lengthy string is being returned as undefined

We are currently in the process of developing an Angular 1.x application that utilizes Bootstrap components. Recently, we integrated Sentry debugging into our site and encountered the following error: 'PAPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDIN ...

"Make sure to specify Safari input field as an email and mark

I am experiencing an issue with a contact form in my HTML/PHP code. Everything seems to be working fine, but when using the SAFARI browser, the form fails to validate if I try to submit without filling out all input fields. For example, my form includes: ...

Ways to eliminate the vertical scroll feature in a kendo chart

I am encountering an issue while loading a kendo chart inside grid-stack.js where I am unable to resize the height properly. Whenever I decrease the height, a vertical scroll appears which should not happen. I have tried setting the height to auto and refr ...

Tips for changing an input value when clicked using JQuery

Struggling to create an interactive mind mapping tool using JQuery? One challenge I'm facing is editing the content of a div once it's been set. I've implemented a function that successfully adds text to a div within the (mind-container). H ...

Switching left navigation in material-ui when the user interacts within the application boundary

I am currently implementing a toggle feature in my AppBar to display the LeftNav. I have successfully set it up to close when the toggle is clicked again. However, I wish to mimic the behavior of most left nav bars where clicking anywhere outside of the ...

Tips for shutting down a modal box without using the "x" button?

I'm currently working on creating a modal box using HTML and Javascript, and I came across this example (reference https://www.w3schools.com/howto/howto_css_modals.asp), which seems to fit my needs quite well... I made some modifications to it... &l ...

Vuejs Error: "No template or render function defined for a single file component"

When attempting to import all components from a folder and display one based on a passed prop, I encountered an error at runtime. I am using webpack with vue-loader to import all my components, each of which is a *.vue file. The issue arises when importi ...

Retrieving the value from a dynamically-generated dropdown menu using jQuery

I created a tree list of data and I am attempting to update some information that is stored in a select element by sending a JSON post request to the edit action. Despite trying multiple approaches with jQuery, myself and my colleagues have been unsuccessf ...

The innerHTML feature in Javascript seems to be malfunctioning

Having a simple javascript issue here. I am attempting to retrieve a date from a textbox and display it in a label for another purpose. However, I encountered some problems along the way. I can successfully alert the date retrieved from the textbox, but wh ...

Why isn't my Vue2 data updating in the HTML?

Starting my journey with Vue, I have been finding my way through the documentation and seeking support from the Vue community on Stack Overflow. Slowly but steadily, I am gaining a better understanding of how to create more complex components. The issue I ...

Passing a variable between two PHP files and then showcasing its value in a separate third file

bookincome.php receives several inputs, and bi.php calculates the total net income based on the values provided by bookincome.php. It then displays a table containing all the user-given values and the calculated total book income ($tnibeforetax) value. How ...

Sorting custom data in a Vue data table, prioritizing null values to be displayed

Currently, in my VueJS v-data-table setup, I am facing a challenge with custom sorting functions. The table has both numeric and string columns, with some null values scattered throughout. My goal is to sort the data by placing null values at the end of ea ...