简体   繁体   中英

How to animate a border?

I want to create a circling border, as seen in the second state of this object. So the loading icon. How would I do that with JavaScript?

I'm not looking for someone writing out the full code, but would like some direction to what selectors etc to research.

https://cdn-images-1.medium.com/max/800/1*JNE8gIhMViaL-Yri9SiCjg.gif

Is quite easy. Basically you start with a circle with a certain width and height, a full border-radius and a transition to it. Then on hover for example, you increase the width of that circle. Doing this will smootly transform that circle into a rectangle. If you dont manage to make it work, i`l create some examples for you.

Take a look at this(hover on the circle)

 div { width: 50px; height: 50px; border: 3px solid green; border-radius: 30px; margin:0 auto; transition: .5s; } div:hover{ width: 200px; background-color: green; } 
 <div></div> 

From here on you can modifiy it to fit your needs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM