Dynamic circuit animation in motion

I have a div on my website with margins only, and I'm looking to create a cool effect when the page loads. I want it to look like there is a circuit running through the div, starting from the positive terminal (where a battery image overlaps the div) and changing color to yellow as it moves towards the negative terminal. I'm not sure if this can be done using CSS alone, but I'm intrigued by its possibilities.

Below is the code for my div tag:

#circuit {
  width: 80%;
  border: 10px solid navy;
  margin: 25px;
  height: 80%;
  margin-left: auto;
  margin-right: auto;
}
html,
body {
  height: 100%;
  margin: 0;
}
<div id="circuit"></div>

Answer №1

To achieve the desired speed, a series of keyframe animations must be utilized with modifications to the duration and cumulative delay.

Check out the live demo on Fiddle

    html, body {
    height: 100%;
    padding: 0;
    margin: 0;
}
* {
    box-sizing: border-box;
}
.circuit-outer {
    position: relative;
    width: 80vw;
    height: 80vh;
    margin: 5% 10% 0;
    padding: 3px;
    background: #eee;
    border: 1px solid #ddd;
    overflow: hidden;
}
.circuit-inner {
    position: absolute;
    top: 3px;
    bottom: 3px;
    left: 3px;
    right: 3px;
    background: #fff;
    border: 1px solid #ddd;
}
.current {
    background: orange;
    position: absolute;
    -webkit-animation-iteration-count: 1;
    -webkit-animation-timing-function: linear;
    -webkit-animation-fill-mode: forwards;
    animation-iteration-count: 1;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
}
.current.bottom-left {
    bottom: 0;
    right: 80%;
    width: 20%;
    height: 3px;
    -webkit-animation-name: zap1;
    -webkit-animation-duration: .2s;
    animation-name: zap1;
    animation-duration: .2s;
}
.current.left {
    bottom: 0;
    left: 0;
    width: 3px;
    height: 0;
    -webkit-animation-name: zap2;
    -webkit-animation-delay: .2s;
    -webkit-animation-duration: .5s;
    animation-name: zap2;
    animation-delay: .2s;
    animation-duration: .5s;
}
.current.top {
    top: 0;
    width: 0;
    height: 3px;
    -webkit-animation-name: zap3;
    -webkit-animation-delay: .7s;
    -webkit-animation-duration: 1s;
    animation-name: zap3;
    animation-delay: .7s;
    animation-duration: 1s;
}
.current.right {
    top: 0;
    right: 0;
    width: 3px;
    height: 0;
    -webkit-animation-name: zap2;
    -webkit-animation-delay: 1.7s;
    -webkit-animation-duration: .5s;
    animation-name: zap2;
    animation-delay: 1.7s;
    animation-duration: .5s;
}
.current.bottom-right {
    bottom: 0;
    right: 0;
    width: 0%;
    height: 3px;
    -webkit-animation-name: zap4;
    -webkit-animation-delay: 2.2s;
    -webkit-animation-duration: .8s;
    animation-name: zap4;
    animation-delay: 2.2s;
    animation-duration: .8s;
}
@-webkit-keyframes zap1 {
    0% {
        width: 0;
    }
    100% {
        width: 20%;
    }
}
@keyframes zap1 {
    0% {
        width: 0;
    }
    100% {
        width: 20%;
    }
}
@-webkit-keyframes zap2 {
    0% {
        height: 0;
    }
    100% {
        height: 100%;
    }
}
@keyframes zap2 {
    0% {
        height: 0;
    }
    100% {
        height: 100%;
    }
}
@-webkit-keyframes zap3 {
    0% {
        width: 0;
    }
    100% {
        width: 100%;
    }
}
@keyframes zap3 {
    0% {
        width: 0;
    }
    100% {
        width: 100%;
    }
}
@-webkit-keyframes zap4 {
    0% {
        width: 0;
    }
    100% {
        width: 80%;
    }
}
@keyframes zap4 {
    0% {
        width: 0;
    }
    100% {
        width: 80%;
    }
}
<div class="circuit-outer">
  <div class="current bottom-left"></div>
  <div class="current left"></div>
  <div class="current top"></div>
  <div class="current right"></div>
  <div class="current bottom-right"></div>
  <div class="circuit-inner"></div>
</div>

Answer №2

Would you like to achieve a similar effect? This code snippet creates a dynamic background and animates its position on hover. You can easily add a custom class when the page loads.

#circuit {
  width: 80%;
  border: 10px solid navy;
  margin: 25px;
  height: 80%;
  margin-left: auto;
  margin-right: auto;
  
  background: linear-gradient(to right, yellow 50%, blue 50%);
  background-size: 200% 100%;
  background-position:right bottom;
  transition:all 2s ease;
}
html,
body {
  height: 100%;
  margin: 0;
}

#circuit:hover {
  background-position:left bottom;
}
<div id="circuit"></div>



Answer №3

Could this be what you are seeking?

#diagram {
  position: absolute;
  width: 300px;
  height: 200px;
  margin: 5% auto;
  border:1px solid;
  
  background: linear-gradient(to right, green 50%, purple 50%);
  background-size: 150% 100%;
  background-position:right bottom;
  transition:all 2s ease;
 
}
html,
body {
  height: 100%;
  margin: 0;
}

#diagram:hover {
  background-position:left bottom;
}
.section{
background:white;
position:absolute;
top:10%;
left:5%;
bottom:10%;
right:5%;
 }
<div id="diagram"><div class='section'></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

Tips for utilizing JavaScript getElementByClassName to retrieve all the elements within a ul without having to specify the class name in each li

Looking to tidy up my HTML/CSS. Is there a way to keep this JavaScript functioning without needing to add the class name to every li element within the ul? Any suggestions on how to improve the visual appeal and readability of the HTML code? const Profi ...

Issue with undefined Sass variable when using Global Sass variable in Vue 3 with Vite: [sass] Undefined variable error

https://i.sstatic.net/7K0uF.png Greetings! I have embarked on the journey of migrating a Vue application from Webpack to Vite. To kick things off, I am starting with a small project. However, I seem to be encountering an error: '[sass] Undefined var ...

Why isn't Bootstrap validation functioning properly in my Modal?

I am attempting to implement client-side validation using bootstrap, as outlined here: https://getbootstrap.com/docs/4.0/components/forms/#custom-styles The challenge I'm facing is that my form is within a modal. When I click the submit button, nothi ...

Enhance Your Profile with Bootstrap 4 Dropdowns

I am trying to incorporate a dropdown profile into my navbar, but it is not appearing where it should be located: pic1 <link href="https://bootswatch.com/4/materia/bootstrap.min.css" rel="stylesheet"/> <script src="https://code.jquery.com/j ...

Modify the transparency of a form's backdrop without affecting the input fields

I'm attempting to achieve a similar effect as shown in this example on my website form. I've tried using opacity to make the form field background only 20% visible, but it ends up affecting the text inside and when typing. Is there a way to apply ...

The Label in Material UI TextField is appearing on top of the border,

Incorporating Material UI TextField and Material UI Tab, I have encountered an issue. There are two tabs, each containing a text field. Upon clicking on the TextField, the label's border is supposed to open, but this behavior only occurs if the curren ...

How can CSS be used to change the text color of input placeholder in Edge Browser?

While using Edge Browser, I encountered an issue where I was unable to change the input placeholder color. The :-ms-input-placeholder selector was not working on Edge, although it functioned properly on IE 10 and IE 11. input:-ms-input-placeholder { ...

Struggling to create a dynamic design for a nested column using bootstrap

After creating a layout in Figma, I have set up a grid structure as follows: <div class="container-fluid"> <div class="row" id="sobre-nos-wrapper"> <div class="col"> <div class="row"> <div class="col ...

What is the best way to design unconventional grids using Bootstrap 4?

Is it possible to achieve unique grid layouts in Bootstrap 4? For instance, An irregular grid where the first column covers two rows, followed by two rows with three columns each |||||||||||||||| | | | | | | |_ |_ |_ | | | | | | |_____| ...

Increasing Gap between Tabs in Primefaces AccordionPanel: A Guide

Is there a way to increase the spacing between the tabs of a Primefaces AccordionPanel component? ...

Bootstrap 4: Embrace the seamless flow of columns with no gaps in

Recently, I encountered an issue with columns in Bootstrap 4. Despite writing the code correctly, there appears to be no space between the 3 blocks displayed in the browser. Each block consists of 4 columns, but they seem to be directly adjacent to each ot ...

Comparing Yii's CHtml::link() function with the use of regular <a href=''></a> HTML tags

When using elements like yii CHtml::link, what are the recommended practices? I'm working on a button that needs to include an icon, text, respond to hover events, and be wide. Are there any benefits to using CHtml instead of a regular tag that can e ...

Utilizing an array of font styles in a single line while maintaining a consistent width

I am creating a simple webpage with fixed width text. Check out this sample HTML: <div id ="wrap"> <h1>An Annoying Heading</h1> <p>Some text some text some text some text some text some text some text some text some text so ...

`Center the image on top of the text`

Currently, I am working with Bootstrap 4 to create a component that includes two tiles. Each tile has an icon image on the left side and a hyperlink on the right side. On desktop view, the tiles should be displayed horizontally and vertically centered. How ...

Show Struts2 error message on an HTML webpage

I have included error and message handling in my Struts2 action class using the addActionMessage and addActionError methods. I am now looking for code that will allow me to display these messages and errors on the HTML page. Is it feasible to do so? ...

Adding a <span> element within an <h1> tag in WordPress

I am attempting to create this layout in Wordpress using the code <h1>This is my <span>title</span></h1>, but I am unsure how to incorporate a <span> tag within the <?php the_title(); ?> function. After consulting the c ...

Using a video as a background in HTML

My code has an issue where I have set overflow: hidden in the CSS but the video is still not displaying below the text as intended. The relevant CSS snippets are: fullscreen-bg { top: 0; right: 0; bottom: 0; left: 0; overflow:hidden ...

Tips for aligning column components in a vertical position

My task is to align vertically the elements within multiple columns that include a headline, a description, and a button. By default, each element expands based on its content size https://i.stack.imgur.com/RJJP4.png However, I need all elements to be al ...

Struggling with proper vertical alignment using Flexbox and achieving center alignment

I've been using JavaScript for displaying dynamic text and images, but I'm facing some formatting issues. Currently, I'm utilizing display: flex to position the text and image next to each other, but I'm struggling with horizontal alig ...

Combine collapse and popover in Bootstrap 3 for enhanced functionality

I'm facing some issues trying to use the badge separately from the collapse feature. $(function (e) { $('[data-toggle="popover"]').popover({html: true}) }) $('.badge').click($(function (e) { e.stopPropagation(); }) ) Check o ...