用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - javascript代码库

圆周运动

2012-09-29 作者: 神马举报

[javascript]代码库

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>圆周运动</title>
<style>
body {
    background:#16171B;
}
#demo {
    width:100px;
    height:100px;
    border-radius:100px;
    border:3px solid #D6D8ED;
    margin:50px auto;
    box-shadow:inset 10px 10px 10px #0B090C, inset -10px -10px 10px #0B090C, 3px 0px 60px rgba(74, 94, 157, .8), 0px -5px 60px rgba(74, 94, 157, .8);
    position:absolute;
    top:300px;
    left:500px;
    background-color: #999;
}
</style>
</head>
<body>
<div id="demo"> </div>
<script type="text/javascript">
function circle(id, R, speed, time) {
    speed = speed || 10;
    time = time;
    var x = document.getElementById(id).offsetLeft;
    var y = document.getElementById(id).offsetTop;
    var step = 1;
    var r = 1;
    var timer = setInterval(function() {
        r = r + 1;
        if (r > R) {
            r -= 1;
        }
        if (step == 360) {
            step = 1;
        }
        if (time != undefined) {
            setTimeout(function() {
                clearInterval(timer);
            }, time);
        }
        document.getElementById(id).style.left = x + r * Math.sin(step) + "px";
        document.getElementById(id).style.top = y + r * Math.cos(step) + "px";
        step -= speed / 100;
    }, 1);
}
circle("demo", 300, 1);
</script>
</body>
</html>


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...