August 17, 2013

Snake-Like Moving Glow around an element

Dan Benjamin’s Question:

I am wondering how can you build a “snake like” effect around the rim of an object using javascript/css.

This effect will create an ever going animation around an object that looks like a tiny white slug moving on the rim of the object (looking like a glow)

(Will Edit this Question once I learn the correct phrasing)

I have a small CSS3 version of this:

A small container and an our snake:

<div id="cont"></div>
<div class="snake"></div>

And here is the CSS Magic:

#cont {
    width: 150px;
    height: 150px;
    background: #000;
    margin: 10px;
}
.snake {
    width: 5px;
    height: 5px;        
    background: #f00;
    position: absolute;
    top: 5px;
    left: 15px;
    animation: around 5s infinite;
}
@keyframes around
{
    0% { left: 15px; top: 5px; }
    25% { left: 165px; top: 5px;  }
    50% { top:  160px; left: 165px; }
    75% { left: 15px; top: 160px; }
    100% { top: 5px; left: 15px; }
}

[Demo]

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!