Smooth transition of an arrow moving in a continuous loop using CSS animations

I am attempting to create a seamless loop of a single arrow within a div.

My approach involves using two SVG arrows in such a way that when the top part of the first arrow is hidden, the corresponding section of the second arrow should be displayed. This would give the illusion that only one arrow is being used, continuously moving in a loop (as the first arrow disappears at the top, the second arrow's equivalent section should appear at the bottom).

.arrows-wrapper {
  width: 124px;
  height: 83px;
  overflow: hidden;
  position: relative;
  background-color: gray;
}

.arrows-wrapper svg {
  position: absolute;
}

.arrows {
  animation: slide 4s linear infinite;
}

.arrow2 {
  animation-delay: 2s;
}

@keyframes slide {
  from {
    transform: translate(0, -25px);
  }
  to {
    transform: translate(0, -125px);
  }
}
<div class="arrows-wrapper">
  <svg width="124" height="197" viewBox="0 0 124 197">
    <g class="arrows arrow1">
      <polyline stroke="yellow" stroke-width="2" fill="none" points="50,110 61,104 72,110"></polyline>
      <polyline stroke="yellow" stroke-width="4" fill="none" points="50,116 61,110 72,116"></polyline>
      <polyline stroke="yellow" stroke-width="2" fill="none" points="50,122 61,116 72,122"></polyline>
    </g>
  </svg>
  <svg width="124" height="197" viewBox="0 0 124 197">
    <g class="arrows arrow2">
      <polyline stroke="yellow" stroke-width="2" fill="none" points="50,110 61,104 72,110"></polyline>
      <polyline stroke="yellow" stroke-width="4" fill="none" points="50,116 61,110 72,116"></polyline>
      <polyline stroke="yellow" stroke-width="2" fill="none" points="50,122 61,116 72,122"></polyline>
    </g>
  </svg>
</div>

To visualize my progress so far, you can view the demo (note that currently both arrows are visible simultaneously, but ideally only one arrow or a portion of it should be visible at any given time).

The desired outcome looks like this: https://i.sstatic.net/HGNnZ.jpg

My question is whether achieving this result is feasible.

Answer №1

To make it work perfectly, all you need to do is adjust the translate function in your CSS animation.

.arrows-wrapper {
  width: 124px;
  height: 83px;
  overflow: hidden;
  position: relative;
  background-color: gray;
}

.arrows-wrapper svg {
  position: absolute;
}

.arrows {
  animation: slide 4s linear infinite;
}

.arrow2 {
  animation-delay: 2s;
}

@keyframes slide {
  from {
    transform: translate(0, -25px);
  }
  to {
    transform: translate(0, -200px);
  }
}
<div class="arrows-wrapper">
  <svg width="124" height="197" viewBox="0 0 124 197">
    <g class="arrows arrow1">
      <polyline stroke="yellow" stroke-width="2" fill="none" points="50,110 61,104 72,110"></polyline>
      <polyline stroke="yellow" stroke-width="4" fill="none" points="50,116 61,110 72,116"></polyline>
      <polyline stroke="yellow" stroke-width="2" fill="none" points="50,122 61,116 72,122"></polyline>
    </g>
  </svg>
  <svg width="124" height="197" viewBox="0 0 124 197">
    <g class="arrows arrow2">
      <polyline stroke="yellow" stroke-width="2" fill="none" points="50,110 61,104 72,110"></polyline>
      <polyline stroke="yellow" stroke-width="4" fill="none" points="50,116 61,110 72,116"></polyline>
      <polyline stroke="yellow" stroke-width="2" fill="none" points="50,122 61,116 72,122"></polyline>
    </g>
  </svg>
</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

Calculating and displaying the output on an HTML page: A step-by-step guide

Within my HTML, I have two values stored in Session Storage: "Money" and "Time". These values are based on what the user inputted on a previous page. For example, if someone entered that they need to pay $100 in 2 days. My goal is to generate a list that ...

Can we incorporate modulo into the loop?

I have a JavaScript function with HTML code inside. I need the ".one-card" div to repeat four times within each ".row" div. The ".row" div is being repeated in a foreach loop. I want to check if the result of modulo (4) is not equal to zero, then display t ...

How can I automatically scroll to an anchor element once CSS animation has finished

I am currently working on a CSS animation that looks like this: @-webkit-keyframes flip { 0% {opacity:1;} 100% {opacity: 0;} //This could be 90% //And here could be frame for 100% which would scroll it down. } #headercover { -webkit-animation-name ...

Leveraging the @font-face feature along with fonts sourced from fontsquirrel

As I embark on creating my very first website, I find myself delving into the world of fonts from Font Squirrel. However, a challenge arises as I realize that not all the fonts I downloaded from the site are easy to use. The real struggle comes when deal ...

What is the method for a HTML button to trigger the execution of a Selenium (Java) code located in a remote location through a

I need to run a Selenium Code written in Java from a NAS (Network Attached Storage) or another connected machine. My goal is to create a web page with a button that, when clicked, triggers the execution of the Selenium script located on the connected mac ...

The typewriter effect is configured to appear as a separate layout,

<div className= "HomePage-typewriter"> I do{'\u00A0'} <Typewriter options={{ strings: [ '<span> this </span>', '<span> that </span>', '<span&g ...

Creating an HTML form that adjusts its size and layout based

Struggling to make my HTML Form responsive - it displays well on desktops, but not on mobile devices or tablets. Want to take a look at the code? Here's the link: JSFiddle I've attempted removing overflow: hidden and white-space: nowrap; from t ...

What are some ways to customize the appearance of React Semantic components?

Is there a way to apply CSS for react semantic UI when using create react app? I have installed semantic-ui-react and included the CSS CDN: loginForm.js: import React from "react"; import { Button, Form, Header } from "semantic-ui-react"; import styles f ...

Activate the textbox without utilizing `.focus()` method

I am encountering an issue with a small iframe on my page. The content within the iframe is larger than the window itself, requiring users to scroll around to view it in its entirety. Within this iframe, there is a button that, when clicked, triggers an an ...

Comparison of button text alignment: stacking vs inline placement

I currently have a button on my webpage labeled "Learn More." Unfortunately, the text on the button is not lining up as it should. Instead of flowing in a line, the text seems to be stacking on top of each other. The HTML code for the button is included ...

A guide on grouping an entire CSS file under one class umbrella

Is there a way to encapsulate a large number of CSS declarations so they only apply when the parent has a specified class? div { color: #ffffff; } ... a { color: #000000; } Can it be structured like this, with a parent class containing all the CSS r ...

Creating visually appealing website designs with Firefox by implementing smooth background image transitions using Javascript with

Currently, I am facing an issue with the banner area on my website. The background of the banner is set to change every 10 seconds using JavaScript. However, there seems to be a flickering effect that occurs for a brief moment when the background-image is ...

Retrieve the initial image link from a blogger's post in cases where it is not being stored on the Blogger platform for use in related

I am currently using a hosting service to store the images that I include on my blogger platform. However, I have encountered an issue where blogger does not automatically fetch the image url to use as the thumbnail when the image is hosted externally. C ...

An error was encountered involving an unexpected token < at the beginning of a JSON file while using express with firebase

After setting up an authentication system in express using firebase auth, I established an endpoint in my express server: app.post('/users/login', (req, res) => { console.log('logging in...'); firebase.auth().signInWithEmail ...

Could you show me how the easyrtcid is generated in the demonstration of audio-only chat? I would appreciate a step-by

Currently, I am utilizing the easyrtc webpage to test out the audio only chat demo and everything seems to be running smoothly. However, when connecting, the easyrtcid variable is automatically assigned a random string. I was wondering if there is a way t ...

Create an element that spans the entire width of the page

Having trouble adjusting the width of the .navbar? It seems to only grow to one side and setting it to 100% width doesn't expand it to fill the whole page. Can anyone provide some guidance or assistance? Here's the code: return ( <div cla ...

Incomplete Loading of Google Maps

Let me clarify that the solutions I have come across so far have not been successful. I am attempting to display a modal alert with a basic Google Maps integration. Problem: Google Maps does not load completely. Snippet from my .js file: var map; functi ...

Tips for incorporating user-entered data from a text box into a JavaScript function and utilizing a loop

Although my code is functioning correctly, I am looking to make some adjustments but seem to be struggling to achieve the desired outcome. Essentially, I have two labels and an input field in which the user is prompted to enter a specific number of weeks ...

Ways to eliminate the dotted line from the image map in Internet Explorer 11

Below you will find the code I am working with: <img alt="Testing 2015" border="0" src="images/Test-2015.jpg" usemap="#Map" /> <p><map name="Map"><area coords="790,100,653,135" href="http://www.google.com/" shape="rect" style="cursor ...

does not output any console log statements

I am attempting to showcase the values of checkboxes on the console, however, it is not working. <input type="checkbox" id="id_price" value="1" onclick="display_img()">Under £200<br> <input type="checkbox" id="id_pr ...