×

WOW,一个很不错的风扇式旋转动画

作者:andy0012017.01.13来源:Web前端之家浏览:18913评论:0
关键词:css3动画

WOW,一个很不错的风扇式旋转动画

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>拖拽并旋转</title>
        <style>
            * {
                padding: 0;
                margin: 0;
            }
            
            #div1 {
                width: 200px;
                height: 200px;
                background: yellow;
                position: absolute;
                border-radius: 100px;
                /*设置旋转秒数*/
                transition: transform 5s;
            }
            
            #div1 div {
                width: 100px;
                height: 100px;
                float: left;
                border-radius: 50px;
                background: white;
            }
            
            #div1:hover {
                /*开始旋转 (360*12圈)4320deg(度) */
                transform: rotate(4320deg);
            }
        </style>
        <script>
            window.onload = function() {
                var oDiv = document.getElementById('div1');
                var x = 0;
                var y = 0;
                oDiv.onmousedown = function(ev) {
                    var oEvent = ev || event;
                    x = oEvent.clientX - oDiv.offsetLeft;
                    y = oEvent.clientY - oDiv.offsetTop;
                    document.onmousemove = function(ev) {
                        var oEvent = ev || event;
                        var l = oEvent.clientX - x;
                        var t = oEvent.clientY - y;
                        var doc = document.documentElement;
                        if(l < 0) {
                            l = 0;
                        } else if(l > (doc.clientWidth - oDiv.offsetWidth)) {
                            l = doc.clientWidth - oDiv.offsetWidth;
                        }
                        if(t < 0) {
                            t = 0;
                        } else if(t > (doc.clientHeight - oDiv.offsetHeight)) {
                            t = doc.clientHeight - oDiv.offsetHeight;
                        }
                        oDiv.style.left = l + 'px';
                        oDiv.style.top = t + 'px';
                    }
                    document.onmouseup = function() {
                        document.onmousemove = null;
                        document.onmouseup = null;
                    }
                    return false;
                }
            }
        </script>
    </head>
    <body>
        <div id="div1">
            <div></div>
            <div></div>
            <div></div>
            <div></div>
        </div>
    </body>
</html>

您的支持是我们创作的动力!
温馨提示:本文作者系 ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://www.jiangweishan.com/article/biji015.html

网友评论文明上网理性发言 已有0人参与

发表评论: