Move dots or points smoothly from a starting position to their destination

How can I achieve animation using SVG or CSS?

The animation should involve the following:

Initially, only lines will be visible (picture 1). After 2 seconds, dots (.) will appear and join the line curves with some animated movement to the dots (picture 2).

View Online Example

Please refer to the code below for implementation details.

SVG Code:

<?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
 <!-- Rest of the SVG code is displayed here -->

Picture 1: (Initial Screen)

Picture 2: (After Animation Effect)

Answer №1

Utilizing SVG

An example of using animateTransform is demonstrated in the following code snippet. The circles' center points (cx and cy) are initially translated along the Y axis (by 100px), then animated back to their original position.

polyline {
  stroke: black;
  stroke-width: 1;
  fill: transparent;
}
.container {
  overflow: hidden;
  height: 200px;
  width: 200px;
  border: 1px solid;
}
svg {
  height: 100%;
  width: 100%;
}
<div class="container">
  <svg viewBox='0 0 100 100'>
    <polyline points='25,35 33,75 50,33 89,22 15,65' />
    <circle cx='25' cy='35' r='2'>
      <animateTransform attributeName="transform" attributeType="XML" type="translate" from="0 -100" to="0 0" dur="2s" />
    </circle>
    <circle cx='33' cy='75' r='2'>
      <animateTransform attributeName="transform" attributeType="XML" type="translate" from="-100 100" to="0 0" dur="2s" />
    </circle>
    <circle cx='50' cy='33' r='2'>
      <animateTransform attributeName="transform" attributeType="XML" type="translate" from="0 100" to="0 0" dur="2s" />
    </circle>
    <circle cx='89' cy='22' r='2'>
      <animateTransform attributeName="transform" attributeType="XML" type="translate" from="100 100" to="0 0" dur="2s" />
    </circle>
  </svg>
</div>

To optimize re-usability with patterns or behaviors for multiple elements, the use element can be employed as shown below.

polyline {
  stroke: black;
  stroke-width: 1;
  fill: transparent;
}
.container {
  overflow: hidden;
  height: 100%;
  width: 100%;
  border: 1px solid;
}
svg {
  height: 100%;
  width: 100%;
}
<div class="container">
  <svg viewBox='0 0 100 100'>
    <defs>
      <g id='circle'>
        <circle r='2'>
          <animateTransform attributeName="transform" attributeType="XML" type="translate" from="0 -100" to="0 0" dur="2s" />
        </circle>
      </g>
      <g id='circle2'>
        <circle r='2'>
          <animateTransform attributeName="transform" attributeType="XML" type="translate" from="100 0" to="0 0" dur="2s" />
        </circle>
      </g>
      <g id='circle3'>
        <circle r='2'>
          <animateTransform attributeName="transform" attributeType="XML" type="translate" from="0 100" to="0 0" dur="2s" />
        </circle>
      </g>
    </defs>
    <polyline points='25,35 33,75 50,33 89,22 15,65 0,10 90,90' />
    <use x='25' y='35' xlink:href='#circle' />
    <use x='33' y='75' xlink:href='#circle2' />
    <use x='50' y='33' xlink:href='#circle' />
    <use x='89' y='22' xlink:href='#circle2' />
    <use x='0' y='10' xlink:href='#circle3' />
    <use x='0' y='10' xlink:href='#circle3' />
  </svg>
</div>


CSS Approach

If CSS is a requirement, you can group polylines within one container div, circular points within another, and animate the latter's transition using keyframes and transform.

polyline {
  stroke: black;
  stroke-width: 1;
  fill: transparent;
}
.container {
  position: relative;
  overflow: hidden;
  height: 200px;
  width: 200px;
  border: 1px solid;
}
svg {
  height: 100%;
  width: 100%;
}
.points,
.lines { 
  position: absolute;
  top: 0px;
  left: 0px;
  height: 100%;
  width: 100%;
}
.points {
  transform: translateY(100%);
  animation: movepoints 1s ease forwards;
}
@keyframes movepoints {
  0% {
    transform: translateY(100%);
  }
  100% {
    transform: translateY(0%);
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>

<div class="container">
  <div class="lines">
    <svg viewBox='0 0 100 100'>
      <polyline points='25,35 33,75 50,33 89,22 15,65' />
    </svg>
  </div>
  <div class="points">
    <svg viewBox='0 0 100 100'>
      <circle cx='25' cy='35' r='2' />
      <circle cx='33' cy='75' r='2' />
      <circle cx='50' cy='33' r='2' />
      <circle cx='89' cy='22' r='2' />
    </svg>
  </div>
</div>

Please note that positioning child elements absolutely within a percentage-based parent may cause issues if parent heights are not explicitly defined due to the absolute positioning. To ensure proper functionality with 100% dimensions set on the container, only absolutely position the div containing the circular points.

polyline {
  stroke: black;
  stroke-width: 1;
  fill: transparent;
}
.container {
  position: relative;
  overflow: hidden;
  height: 100%;
  width: 100%;
  border: 1px solid;
}
svg {
  height: 100%;
  width: 100%;
}
.points,
.lines {
  height: 100%;
  width: 100%;
}
.points {
  position: absolute;
  top: 0px;
  left: 0px;
  transform: translateY(100%);
  animation: movepoints 1s ease forwards;
}
@keyframes movepoints {
  0% {
    transform: translateY(100%);
  }
  100% {
    transform: translateY(0%);
  }
}

*{
  margin: 0;
  padding: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div class="container">
  <div class="lines">
    <svg viewBox='0 0 100 100'>
      <polyline points='25,35 33,75 50,33 89,22 15,65' />
    </svg>
  </div>
  <div class="points">
    <svg viewBox='0 0 100 100'>
      <circle cx='25' cy='35' r='2' />
      <circle cx='33' cy='75' r='2' />
      <circle cx='50' cy='33' r='2' />
      <circle cx='89' cy='22' r='2' />
    </svg>
  </div>
</div>

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

Hover effect for child element not activating CSS3 Transition

I need my list item to activate a css3 transition on its child element .pusher when it is hovered over. I usually achieve this using JS, but I want to try implementing it with css3 transitions. After reading some other questions on SO, I attempted to do it ...

Is there an issue with the padding not functioning correctly on smaller and medium-sized devices when using Bootstrap

On my desktop, I added '50px' padding to the body of my page and it's working properly. However, on smaller and medium screens, it's not functioning correctly. I tried using Bootstrap @media CSS functionality, but it still doesn't ...

What could be the reason for the gtag event not showing up in Google Analytics?

Here is an example of my script: <html> <head> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxxx-1"></script> <script> wi ...

Encountering persistent issues while attempting to integrate socket.io into my Node.js application with Express

Recently, I've been exploring ways to create a textbox that allows multiple users to type simultaneously. Below is the HTML code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> ...

Send in the completed form with your chosen preferences

Is there a way for me to submit a form with the selected option? My backend code is set up to work when using inputs: <input id="id_value_0" name="value" type="radio" value="1" /> <input id="id_value_1" name="value" type="radio" value="2" /> ...

Tapping elsewhere on the screen will not result in the select box closing

I'm currently troubleshooting an issue with the site filter feature. When the btn-select is open and I click outside the panel, the select remains open. I am looking to create an event that will detect when the dropdown is closed so that I can close t ...

How can I add divs to an HTML page with a Javascript animated background?

I am currently facing an issue with my JavaScript animated background, consisting of just 3 pictures. I am trying to display some Div elements on it with content inside. Here is the code snippet I have right now: In my CSS file, I have defined styles for ...

Ways to restrict the content div JSON display to only three items

Is it possible to limit the display of items from JSON in the content div to just three? The current code displays all downloaded items, but I want only 3 divs to be returned. <div id="p"></div> $.getJSON('element.json', function(d ...

Why are JSON values showing up as undefined in HTML conversion?

I am new to JSON and I am experimenting with the open table of World Cup stats mentioned on this page (http://yhoo.it/ydnworldcup2010). The code below (from a demo I came across, just with some changes to YQL call for getJSON and div names) is returning a ...

Style a CSS underline of an element that is contained within a span

Kindly refer to the information provided below: <span class="caption"> {block:Caption}<p>{Caption}</p><hr>{/block:Caption} </span> The Caption block will include text, with a section of it being a hyperlink. How can I desig ...

If the href is clicked on a mobile device, redirect the user

Check out my website at I wanted to enhance the user experience on my home page by implementing a lightbox feature for the car images. I successfully achieved this using slimbox from <div class="block-link"> <a href="images/page1_image1.jpg" ...

What is the code to incorporate a color using PHP?

Question: Is there a way to indicate approval with green color and decline with red color? I've searched for a solution but couldn't find one. PHP Code: <?php if(isset($_POST['approve'])) { $msg = "Approved"; ...

The div's height is not matching the CSS declaration as expected

In my HTML, I have a div called innerDetails which serves as a flex item with the following CSS properties: .cover { height: 100vh; width: 100%; } #screenCon ...

Changing the background color of the canvas using Javascript

I want to create a rect on a canvas with a slightly transparent background, but I don't want the drawn rect to have any background. Here is an example of what I'm looking for: https://i.stack.imgur.com/axtcE.png The code I am using is as follo ...

Problem encountered while extracting data from HTML structure using indexing

My current task involves scraping data from a specific html structure found on 30-40 webpages, such as the one below: https://www.o2.co.uk/shop/tariffs/sony/xperia-z-purple/: <td class="monthlyCost">£13<span>.50</span></td> ...

The navigation toggler seems to be malfunctioning in the browser, but it is functioning properly on Code

I'm having an issue with my navigation bar toggler. The code works fine in Codeply, but not in the browser. The hamburger button appears on mobile, but the lists are not showing up. Here is the code snippet I'm using: <html> <head> ...

Drupal-add-css is acting non-responsive

When incorporating javascript and css into my project, I am encountering an issue. Here is the code snippet I am using: if( $form['#node']->type == 'e_form' ){ drupal_add_css( drupal_get_path('module', 'e_form&apo ...

Issues with retrieving data from nested nodes while parsing NOAA weather information using Javascript XML

Seeking assistance with my Javascript code, which is designed to extract weather data from NOAA xml files (obtained from this link: ). Currently, I have included a snippet of the XML as a string: var xmlDoc = $.parseXML("<data>\ <weather tim ...

Customize the default classes for DataGrid in Material UI

Attempting to customize the CSS properties in the "DataGrid" Material UI, specifically adjusting font weight and overflow of the header. Below is the JSX code snippet: import React, {useState, useEffect} from 'react'; import {DataGrid, GridToolb ...

Is there a way to implement this toolbar in Ionic Angular?

https://i.sstatic.net/sGd1o.png I am looking to replicate the toolbar shown in the image above using Ionic. As a beginner in Ionic development, I am finding it challenging to translate the design into code. I attempted to use a grid layout, but the varyin ...