Frames of Animation

Seeking assistance in understanding how to create frame animation using JavaScript or CSS. Attempting to replicate the animation seen on this website. Intrigued by the road animation and unsure if it is achieved using a plugin or just JavaScript and CSS.

Answer №1

  1. I converted it into an image using SVG format.
  2. Then I added animation effects using pure HTML5 and CSS3 Animation.
  3. Utilized the .path class along with @keyframes.
  4. Unfortunately, it is not compatible with IE and Safari browsers.

Check out the code below:

.line{
    width: 65%;
    margin: 0 auto;
}

svg{
     display: block;
}

#svg path.path{
    stroke-dasharray: 3000;
    stroke-dashoffset: 4000;
    stroke-width: 2;
    
    -webkit-animation: lines 5s linear forwards;
    -moz-animation: lines 5s linear forwards;
    -ms-animation: lines 5s linear forwards;
    -o-animation: lines 5s linear forwards;
    animation: lines 5s linear forwards;
}

@keyframes lines {
form { stroke-dashoffset: 4000;}
  to { stroke-dashoffset: 0; }  
}

@-webkit-keyframes lines {
form { stroke-dashoffset: 4000;}
  to { stroke-dashoffset: 0; }  
}

@-moz-keyframes lines {
 form { stroke-dashoffset: 4000;}
  to { stroke-dashoffset: 0;}  
}

@-ms-keyframes lines {
 form { stroke-dashoffset: 4000;}
  to { stroke-dashoffset: 0; }
}

@-o-keyframes lines {
 form { stroke-dashoffset: 4000;}
  to { stroke-dashoffset: 0; }

}
<div class="line">
  <svg id="svg" stroke="#000" stroke-miterlimit="1000" id="Layer_1" style="opacity:1;" x="0px" y="0px" viewBox="0 0 960 560" enable-background="new 0 0 960 560" xml:space="preserve">
    <path class="path" fill="#fff" stroke="#000" stroke-miterlimit="1000" stroke-dasharray="11.9901,11.9901" d="M52.652,248.08
c30.97,37.245,74.957,63.396,122.172,75.244c53.056,13.313,109.816,9.162,161.756-7.968
c42.308-13.953,83.007-37.533,108.174-74.156c4.655-6.774,8.818-14.153,10.027-22.271c2.24-15.044-6.187-29.969-17.51-40.177
c-28.483-25.679-73.116-26.422-108.534-11.588c-54.196,22.698-92.323,81.422-86.252,139.649
c6.07,58.228,59.091,109.265,117.886,109.022c20.716-0.085,41.065-5.884,60.092-14.042c18.307-7.85,35.789-18.023,50.322-31.606
c14.503-13.555,25.718-30.139,37.837-45.845c17.476-22.649,37.883-44.311,64.254-55.552c26.37-11.241,59.879-9.795,80.612,9.943
c30.67,29.196,23.317,84.899,56.145,111.668c29.1,23.729,74.437,10.683,102.618-14.121c32.31-28.438,51.374-68.875,65.118-109.573
c12.464-36.907,21.327-75.103,35.836-111.202" />
  </svg>
</div>

View the code on "Code Pen"

I hope this explanation was helpful. Feel free for anyone to modify the code to make it compatible with IE and Safari browsers.

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

Transforming HTML Code in a PHP Document to a PDF Document

I have a PHP file that interacts with a database to update the HTML content. There is a button on the page labeled "Export As PDF". I attempted to convert the page to a PDF using HTML2FPDF, but encountered this error message: FPDF error: Unable to create ...

Guide on merging non-modular JavaScript files into a single file with webpack

I am trying to bundle a non-modular JS file that uses jQuery and registers a method on $.fn. This JS must be placed behind jQuery after bundling. Here is an example of the structure of this JS file: (function($){ $.fn.splitPane = ... }(JQuery) If y ...

Ensure images are correctly aligned

Could really use some help with this issue I'm having. It's probably a simple fix for all you experts out there, but I can't seem to align my images properly so they are even and not one higher than the other. Please take a look at the scree ...

Using Jquery to dynamically add or remove a class based on scrolling behavior

Can someone help me with identifying the position of an element so that when the user scrolls to it and it appears on the screen, an icon can be highlighted? Currently, the script I am using adds the class too early, closer to the bottom of the block. I w ...

Changing the story in javascript

I am trying to customize the legend to display the following values: 80+ (or 80%+) 75-80 70-75 65-70 60-65 55-50 <50% While I have organized the list in descending order, I seem to be facing an issue with getting the less than symbol to function correct ...

javascript date.js parsing and sorting an array of objects

I'm currently working on creating a JavaScript array of objects, utilizing date.js to parse dates, and then sorting that array using date.js compare methods. Below is a snippet of code that highlights the two issues I am facing. Issue 1: How can I ha ...

Unable to generate a fresh directory with mongoose and express

As the title suggests, I am working on an application that generates a link using mongoose _id and express's app.get when certain information is inputted. However, I am facing an issue where I have to reload the entire server in order to access the di ...

HTML // jQuery - temporarily mute all audio for 10 seconds after page reload

Is there a way to automatically mute all audio sounds on my website for the first 10 seconds after it is reloaded, and then unmute again? <audio id="musWrited" autoplay> <source src="sound/soundl.mp3" type="audio/mp3" /> // < ...

The compatibility between cross-fetch and React Native is currently not supported

I have developed an API wrapper that utilizes fetch to carry out the API requests. To ensure compatibility with Browsers, Node, and React Native, I incorporate cross-fetch. When testing the wrapper in Node, everything works fine. However, when using it in ...

Why isn't P5.JS's .display() working like it should?

I'm having trouble figuring out the scope of this code. I moved the function around, but I keep getting a "not a function" error. let bubbles = []; function setup() { createCanvas(400, 400); for (let i = 0; i < 10; i++){ bubbles[i] = new Bubbl ...

How do I ensure a single row in my table constantly remains at the bottom?

I am currently working on developing a MUI table that shows rows, with the last row displaying the total number of colors. The challenge I am facing is ensuring that the last row always stays at the bottom when there are no results in the table. I have att ...

Parsing HTML to access inner content

Currently, I have integrated an onClick event to an anchor tag. When the user interacts with it, my objective is to retrieve the inner HTML without relying on the id attribute. Below is the code snippet that illustrates my approach. Any assistance in acc ...

Ways to stop user authentication in Firebase/Vue.js PRIOR to email verification

I am currently working on a Vue.js and Firebase authentication interface with an email verification feature. The setup is such that the user cannot log in until they click the verification link sent to the email address provided during the login process. ...

Ways to align two elements within the same level in the DOM?

Is it really impossible to have two elements render parallel to each other on the z-axis? Even with the same z-index, they are treated as being on different levels based on their order in the DOM. This can be a challenge when trying to display nearby eleme ...

Give it a little time before uploading a widget onto the page

As a newcomer to programming, I recently came across this code from an open source project. I am in the process of loading a widget onto a website. Instead of having the widget load instantly, I would like it to wait 10 seconds before displaying. Below i ...

Wordpress causing Jquery to malfunction; PHP function not executing

Looking to incorporate a script into my WordPress function.php file. Here's what I have so far: <?php function add_google_jquery() { if ( !is_admin() ) { wp_deregister_script('jquery'); wp_register_script('jquery', ...

Updating children of specified parents using jQuery

I have a collection of files in a directory and some file icons need to be changed as the default ones are not specific enough. Due to limitations, I can only achieve this using jQuery to insert the code since the mimetype function cannot be modified. Bel ...

Protecting a Web Function

Suppose I have a C# MVC method to send emails using AJAX, like this: public class EmailController : Controller { SmtpClient mailserver = new SmtpClient("smtp.foo.com"); public string sendEmail(string from, string to, string subject = "", ...

A loop variable in Javascript is a function that iterates

var x = 99; while (true) { function lyrics(person) { return x + " " + "lines of code in the file " + x + " " + person + (x-1) + " lines of code" + "!"; } console.log(lyrics("John strikes one out, clears it all out ;")); x -= 1; if (x ...

The select2 plugin seems to be having trouble recognizing the Li click functionality

I have a select menu that is using the select2 plugin. I am trying to add a class to the <select> element when a menu option is clicked, but it doesn't seem to be working as expected even after testing with an alert. https://jsfiddle.net/ysm4qh ...