掘金的头像旋转模仿实现

1,074 阅读1分钟

受到大佬的感召来到掘金,第一篇文章就写个小东西吧,偶然之间发现掘金个人主页的头像在鼠标悬浮的时候会旋转,旋转速度为主键变快最后变慢直到停止。

代码附上,主要就是通过transform来实现动画效果,然后设定旋转的圈数与动画过渡时间,然后设定速度曲线,这里直接使用了ease,效果是差不多的,就酱~

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>

        #myimg{
            width: 200px;
            height: 200px;
            border-radius: 100px;
            border: 1px grey solid;
        }
        #myimg:hover{
            transform: rotate(300turn);
            transition-duration: 30s;
            transition-timing-function:ease;
        }
    </style>
</head>
<body>
    <div>
        <img id="myimg" src="http://47.100.224.40/imgs/1bee703169678a7875c255670c9de65d.png">
        
    </div>
</body>
</html>