having trouble getting javascript animations to work on html code

I've been experimenting with adding a typing animation to my current HTML document as part of a project I'm working on. Despite following tutorials and guides, the animation is successful when created in separate HTML/CSS documents, but integrating it into my existing project has proven to be challenging.

For this project, I utilized a GitHub repository: https://github.com/mattboldt/typed.js/

To incorporate the typing animation, I cloned the necessary files into a designated folder within my project structure. The location for the file ended up being .\javascript\typed.js

<div id="header">
        <div class="container">
            <nav>
                <img src="images/logo.png" class="logo" alt="">
                <ul id="sidemenu">
                    <li><a href="#header">Home</a></li>
                    <li><a href="#about">About</a></li>
                    <li><a href="#services">Services</a></li>
                    <li><a href="#portfolio">Portfolio</a></li>
                    <li><a href="#contact">Contact</a></li>
                    <i class="fa-solid fa-xmark" onclick="closemenu()"></i>
                </ul>
                <i class="fa-sharp fa-solid fa-bars" onclick="openmenu()"></i>
            </nav>
            <div class="header-text-style">
                <p>im a<span id="animate"></span>
                </p>
                <h1>Hi, i'm <span>Elf</span><br> from the North Pole</h1>
                
            </div>
        </div>
    </div>

Insert at the bottom, within the body section:

<script src="javascript/typed.js"></script>
<script>
    var typed = new Typed('.animate', {
        strings: ["Coding", "Sleeping", "third word"],
        typeSpeed: 150,
        backSpeed: 150,
        loop: true
    })
</script> 
.header-text-style p{
    position: absolute;
    top: 27%;
    left: 100%;
    transform: translate(-50%, -50%);
    width: 100%;
    margin: 0;
    padding: 0;
    font-family: poppins;
    color: green;
    font-size: 4.5em;
    text-shadow: 0 2px 5px rgba(#fff , .5);
}
#animate{
    color: chartreuse;
}

Answer №1

It was pointed out by Tieson that using an id for the element you wish to animate is the correct approach. Remember, the selector for ids is indicated by a #, not a ..

Rather than duplicating and utilizing the files locally, consider using a CDN such as CDNjs to deliver the library (as demonstrated in the jsfiddle).

<script src="https://cdnjs.cloudflare.com/ajax/libs/typed.js/2.0.5/typed.min.js" integrity="sha512-1KbKusm/hAtkX5FScVR5G36wodIMnVd/aP04af06iyQTkD17szAMGNmxfNH+tEuFp3Og/P5G32L1qEC47CZbUQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
var typed = new Typed('#animate', {
    strings: ["Coding", "Sleeping", "third word"],
    typeSpeed: 150,
    backSpeed: 150,
    loop: true
})
</script> 

View the animated JsFiddle here: https://jsfiddle.net/1qwejn40/19/

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

I am unable to retrieve any text from the class as it is returning a null value

Can someone please assist me with two issues I am facing: 1) Firstly, I am trying to match the text of an alert pop-up using the following code: <div class="noty_message message"><span class="noty_text">Uh oh! Email or password is incorrect&l ...

Generating a download hyperlink using the image source attribute in jQuery

I have multiple galleries featuring images with captions. I'm striving to add a download link for each image at the end of its caption, based on the image source. However, I am facing an issue where the download icon is being appended to every image c ...

Enhance user experience by implementing a feature in AngularJS that highlights anchor

As I am in the process of developing a chat application using Angular, I have encountered an issue with switching between views. One view, named 'chat.html', displays the list of available users while another view, 'chatMessages.html', ...

Calculating Time Difference in JavaScript Without Utilizing moment.js Library

I have two timestamps that I need to calculate the difference for. var startTimestamp = 1488021704531; var endTimestamp = 1488022516572; I am looking to find the time difference between these two timestamps in hours and minutes using JavaScript, without ...

How can you refresh a functional component using a class method when the props are updated?

I've created a validator class for <input> elements with private variables error, showMessage, and methods validate and isOk. The goal is to be able to call the isOk function from anywhere. To achieve this, I designed a custom functional compone ...

Facing Issues with Angular 10 Routing on an HTTP Server Deployment?

After successfully running my Angular ver-10 Ecommerce Project locally with "ng serve", I encountered an issue when trying to publish it using "ng-build" and hosting it with "http-server". The problem arises when navigating from the Home Screen (e.g. Dashb ...

Using a twig loop to display just a single table cell

The following twig loop is used to generate data: {% for reservationDate, rooms in data.pricingTable %} <tr> <td> {% for room in rooms %} <tr> <td ...

Utilizing AngularJS to bind data with labels and passing it in a form

I'm having trouble binding input data with label tags and using the same ng-model in a post method. Only one thing works at a time, and when I try to pass the label in the post method, it doesn't work. This issue is causing me difficulty in delet ...

Angular 14 - Issue with passing values through props - Error: Uncaught (in promise): InvalidCharacterError occurs when attempting to set attribute with 'setAttribute' method

I am a beginner with Angular and encountering an issue when trying to pass props from a parent component to a child component. The specific error I am facing is related to an invalid attribute name while using Angular version 14.2.5. core.mjs:7635 ERROR ...

Choose a specific item by its name and retrieve its corresponding identifier using Angular

In my current MVC project using HTML and angular, I am facing an issue with a select list. The list is supposed to be selected based on the name entered in an input box, but unfortunately, I am unable to retrieve the id associated with the selected item. ...

Refreshing the content using AJAX and sending a request to update

I am currently working on a project where I need to fetch data through an ajax call and then send that data back using ajax as well. Here is the javascript code: setInterval (function () { var xmlhttp = new XMLHttpRequest(); var conten ...

Changing the background color of tabs in Angular

Being a beginner in HTML and CSS, I recently utilized the angular-tabs-component to create tabs. Now, I am looking to change the background color of the tab. Can someone guide me on how to achieve this? Below is the code snippet: HTML: <tabs (currentT ...

Introducing the brand new feature: Video Mute Button!

Currently, I am working on implementing a mute button for a video on my webpage. The background of my page consists of a looping video with no other content, but the sound becomes quite bothersome after a while. While I have managed to find a button to pau ...

"Unleashing the power of plugins in your Nuxt.js store: A step

I am facing an issue with my gtag (analytics plugin) where I can access it on my components but not on my store. Any suggestions are welcome. Thank you. plugins/vue-gtag.js import Vue from "vue" import VueGtag from "vue-gtag" export d ...

Tips for initializing store data in vuex before the component is rendered

Currently, I am utilizing Vuex to store a tree structure within the state property. This data is retrieved via an ajax call. The issue arises when the page renders before the variable in the state property has been fully populated. For example: // sth. ...

What is the method for determining the proportional color that falls between the three provided colors using a specified percentage?

After receiving three hexadecimal colors from the user, such as: #39bf26 #c7c228 #C7282E The user then needs to select a percentage between 1 and 100. If the percentage is 100, the color returned will be the first color entered: #39bf26. If the percen ...

Can anyone offer a straightforward method for obtaining JavaScript output in Java within the Eclipse environment?

Currently, I am attempting to retrieve the return value from a JavaScript function that I have created. Although I can achieve this using a complex method involving listeners, I am interested in utilizing Eclipse's Browser.evaluate method. For practi ...

The Bootstrap carousel is experiencing unresponsiveness

While I successfully built a carousel for my clients that works perfectly on non-bootstrap platforms, I encountered some issues when trying to make it responsive on Bootstrap. It seems that there is a JavaScript issue that is preventing it from working pro ...

What is the best way to retain the original display property when using jQuery for animations?

Let me simplify the problem for you: I currently have two divs First div: <div id="first" style="color:black;"></div> Second div: <div id="second" style="color:red;display:inline;"></div> My objective is to activate slideUp on t ...

What is the best way to switch from a React app on port 5173 to another React app on port 5174 while in the development phase?

In my current project setup, there is a backend server along with two separate React applications - a frontend website and a dashboard, each running on different ports. After the user logs in on the website, they have the option to access the dashboard. Ho ...