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

Module is absent in JavaScript but present in TypeScript

As I delve into coding a vscode extension by following a tutorial, I encountered an issue with importing in my server.ts file. The directory structure looks like this: ...

jquery for quick search

<form method="post" action="search.php"> Commence search: <input id="search" type="text" size="30" > <div id="search_results"></div> <script src="//code.jquery.com/jquery-1.12.0.min.js"></script> <script src="//code. ...

css how to style a table row with a specific identifier

Although this question has been asked millions of times on the internet, my English skills are not great and I struggle to find the right words to search. I have a table with a specific ID set up like this: <table class="tableClass"> <tr id="one ...

retrieve the value of a specific key using JSON stringify

[{"displayorder":"1","menuname":"DashBoard","menuid":"5","menuurl":"dashboard.php"},{"displayorder":"3","menuname":"Accounting Module","menuid":"3","menuurl":""},{"displayorder":"4","menuname":"My Profile","menuid":"4","menuurl":"myprofile.php"},{"displayo ...

Please submit the form to log in with your credentials

Here is the HTML code snippet for a form where users can enter their username and password to log in: <form Name ="form1" Method ="POST" ACTION = "userlogin.php" id="form1"> <div id="main_body" class="full-width"> <label>User ...

Struggling with implementing ng-repeat in AngularJS for displaying HTML content

I stumbled upon a post that covers pretty much what I'm trying to achieve: AngularJS - Is it possible to use ng-repeat to render HTML values? Currently, the code appears like this and displays correctly as text: <div ng-repeat="item in items.Item ...

The active class in the Bootstrap carousel is not updating when trying to change

I am struggling to make the Twitter Bootstrap carousel function properly. Although the slides automatically change after the default timeout, the indicators do not switch the active class, resulting in my carousel failing to transition between slides. Ini ...

What is the method for specifying a JSON object within a DOM element's `data` attribute?

In an attempt to store JSON data within a dataset attribute, I encountered the following HTML structure: The appearance of the HTML is as follows <div data-switch="true" data-json="{'key1': 'value 1'}, {'key2': 'valu ...

Using HTML and C# to Deliver Emails

I've encountered a challenge with my HTML page that includes a textbox for users to input their email. When the submit button is clicked, an email should be sent to a specific email address defined in the code, and a pop-up box indicating "Email Sent" ...

Adjust the color of the active link on the page using Angular and CSS

I have a project that I need to modify by adding a sub menu that appears on every page but is only coded once. My goal is to highlight the link for the current page, all within one HTML snippet. Although the list renders correctly, I'm struggling to g ...

Is the AJAX call returning JSON data?

Currently, I am utilizing AJAX technology to scrape player names and their respective ratings from a website. The approach I have chosen involves having AJAX return a JSON object which is then manipulated using jQuery to append each element of the JSON obj ...

Ways to access the innerHTML of a specific HTML element by targeting its class using jQuery

I'm working with HTML code that looks like this: <div class="a">html value 1</div> <div class="a">html value 2</div> Is there a way to retrieve html value 1 and html value 2 using jQuery? ...

Typescript counterpart of a collection of key-value pairs with string keys and string values

Within the API I'm currently working with, the response utilizes a data type of List<KeyValuePair<string, string>> in C#. The structure appears as shown below: "MetaData": [ { "key": "Name", &q ...

AngularJS/Ionic: Issue with HTTP GET requests not completing within a specified timeframe

Attempting to populate options with specific values instead of undefined, but encountering a delay in retrieving the values after the select box has finished loading. https://i.stack.imgur.com/SpEFP.jpg To illustrate, here is the HTML code snippet: < ...

Having difficulty displaying this code accurately on Google Chrome

I managed to create a hover effect over a series of images that displays additional information when hovered over. Below is the code I used: HTML <ul class="photo-grid"> <li> <a href="https://www.abglobal.com/" target="_blank"& ...

Discovering the geographical location of all users using Node.js: A step-by-step guide

My current task involves determining the geoip location of users. I have implemented a code that stores the user's address in the database and then displays the geoip location accordingly. However, if a user changes their location and logs in from a d ...

What is the best way to pause function execution until a user action is completed within a separate Modal?

I'm currently working on a drink tracking application. Users have the ability to add drinks, but there is also a drink limit feature in place to alert them when they reach their set limit. A modal will pop up with options to cancel or continue adding ...

Having trouble transitioning from Curl to Axios in Node.js? Encountering issues when trying to make a curl request using the provided certificates, resulting in ECONNRESET or

I've been struggling to make a successful curl request in Axios (Node.js) without any luck. A typical working curl request I use (can't provide exact details as the API is private) is like this: curl --cacert server.pem --cert client.pem:123pas ...

Encountering issues accessing the key value 'templateUrl' in Angular6

I have an object in my component.ts file that I need to iterate through in the HTML template using a ui-comp-menu element. menuObject = [{ 'labels': 'Content1', 'templateUrl': 'assets/partials/sample.html ...

Methods to prompt a user to select an option using Bootstrap

I have been struggling with this problem for hours and it's really starting to frustrate me! Currently, I am incorporating Twitter Bootstrap along with bootstrap-min.js. This is the code snippet in question: <select id="assettype" name="assettyp ...