Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line drawing animation with pure css

Tags:

css

animation

Is there any way to implement a CSS animation in which a dot grows to be a line?

point l (a dot) ---------------------------> point m (a line)

I know this can be done with SVG, but I want to know if it is possible to be implemented with pure CSS.

like image 467
sawa Avatar asked Oct 12 '16 07:10

sawa


2 Answers

You could use a border on an element with 1px which grows to the required length.

Using @keyframes and animation properties you can get this to start from page load.

div{
  height:0px;
  width:1px;
  border-bottom:1px solid #000;
  
  -webkit-animation: increase 3s;
  -moz-animation:    increase 3s; 
  -o-animation:      increase 3s; 
  animation:         increase 3s; 
  animation-fill-mode: forwards;
}

@keyframes increase {
    100% {
        width: 300px;
    }
}
<div></div>
like image 88
Curtis Avatar answered Oct 21 '22 16:10

Curtis


Using the transition property in CSS, you can give drawing effect to a <div> by targeting its width property.

Hover over the orange color dot on result screen.

.point {
  width: 6px;
  height: 6px;
  background: tomato;
  border-radius: 3px;
  transition: width 1s ease;
}

.point:hover {
  width: 200px;
}
<div class="point"></div>
like image 23
Deepak Yadav Avatar answered Oct 21 '22 18:10

Deepak Yadav