HTML5实现简单圆周运动示例
一、使用JS实现圆周运动
根据指定圆心、半径,在定时器中移动固定的弧度,重绘圆圈的位置
源代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.circle{
width:20px;
height:20px;
background:blue;
border-radius:50%;
position: absolute;
}
.rectangle{
width:300px;
height:300px;
border:1px solid red;
position: relative;
}
</style>
</head>
<body> <div class="rectangle">
<div class="circle"></div>
</div> <script src="../Js/jquery-1.11.3.min.js"></script>
<script>
(function(){
//圆周运动js实现
var circle=$('.circle');
var rect=$('.rectangle');
//获取半径和圆心
var centerX=(rect.width()-circle.width())/2;
var centerY=(rect.height()-circle.height())/2;
var radius=centerX;
//时间递进
var times=0;
//重绘位置
function reset(){
times+=1;
var hudu=(2*Math.PI/360)*times;
//console.info(hudu);
var x=centerX+Math.sin(hudu)*radius;
var y=centerY+Math.cos(hudu)*radius; circle.css({
left:x,
top:y
});
//调用自己
requestAnimationFrame(reset);
}
//启动定时器
requestAnimationFrame(reset);
})();
</script>
</body>
</html>
逆时针旋转效果:

二、使用CSS实现圆周运动
使用transform的rotate方法实现旋转,需要重点设置一下圆心位置
源代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
@keyframes run{
from{
transform:rotate(0deg);
}
to{
transform:rotate(360deg);
}
}
.circle{
width:20px;
height:20px;
background:blue;
border-radius:50%;
position: absolute;
transform-origin:110px 110px;
animation:run 5s linear infinite;
left:40px;
top:40px;
}
.rectangle{
width:300px;
height:300px;
border:1px solid red;
position: relative;
}
</style>
</head>
<body>
<div class="rectangle">
<div class="circle"></div>
</div>
</body>
</html>
顺时针旋转效果:

更多:
HTML5实现简单圆周运动示例的更多相关文章
- html5本地存储之localstorage 、本地数据库、sessionStorage简单使用示例
这篇文章主要介绍了html5本地存储的localstorage .本地数据库.sessionStorage简单使用示例,需要的朋友可以参考下 html5的一个非常cool的功能,就是web stora ...
- LayaAir引擎开发HTML5最简单教程(面向JS开发者)
LayaAir引擎开发HTML5最简单教程(面向JS开发者) 一.总结 一句话总结:开发游戏还是得用游戏引擎来开发,其实很简单啦 切记:开发游戏还是得用游戏引擎来开发,其实很简单,引擎很多东西都帮你做 ...
- 【java开发系列】—— spring简单入门示例
1 JDK安装 2 Struts2简单入门示例 前言 作为入门级的记录帖,没有过多的技术含量,简单的搭建配置框架而已.这次讲到spring,这个应该是SSH中的重量级框架,它主要包含两个内容:控制反转 ...
- Springmvc整合tiles框架简单入门示例(maven)
Springmvc整合tiles框架简单入门示例(maven) 本教程基于Springmvc,spring mvc和maven怎么弄就不具体说了,这边就只简单说tiles框架的整合. 先贴上源码(免积 ...
- hadoop环境安装及简单Map-Reduce示例
说明:这篇博客来自我的csdn博客,http://blog.csdn.net/lxxgreat/article/details/7753511 一.参考书:<hadoop权威指南--第二版(中文 ...
- EasyHook远注简单监控示例 z
http://www.csdn 123.com/html/itweb/20130827/83559_83558_83544.htm 免费开源库EasyHook(inline hook),下面是下载地址 ...
- Web Service简单入门示例
Web Service简单入门示例 我们一般实现Web Service的方法有非常多种.当中我主要使用了CXF Apache插件和Axis 2两种. Web Service是应用服务商为了解决 ...
- 【html5】html5本地简单存储
html5本地简单存储 HTML5 提供了四种在客户端存储数据的新方法,即 localStorage .sessionStorage.globalStorage.Web Sql Database. 前 ...
- Ext简单demo示例
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
随机推荐
- sqlite读写
#coding=utf-8 import sqlite3 import os #创建数据库和游标 if os.path.exists(' test.db'): conn=sqlite3.connect ...
- 014.Zabbix的Agent key
一 常见key 1.1 监控网卡流量的key net.if.{in/out}[if,<mode>] if表示网卡接口,mode表示取值类型. mode参数:bytes(默认),packet ...
- jquery 下拉列表选择值
选择下拉列表值样例方式 $("#updateAppName").get(0).selectedIndex = 0; $("#updateAppName").ge ...
- BZOJ.2595.[WC2008]游览计划(DP 斯坦纳树)
题目链接 f[i][s]表示以i为根节点,当前关键点的连通状态为s(每个点是否已与i连通)时的最优解.i是枚举得到的根节点,有了根节点就容易DP了. 那么i为根节点时,其状态s的更新为 \(f[i][ ...
- Codeforces Round #258 (Div. 2) A. Game With Sticks 水题
A. Game With Sticks 题目连接: http://codeforces.com/contest/451/problem/A Description After winning gold ...
- AVR Programming Methods
AVR Programming Methods There are many ways to program AVR microcontrollers. Since many people ask ...
- HOWTO: Use STM32 SPI half duplex mode
HOWTO: Use STM32 SPI half duplex mode I’ve got my hands onto some STM32F030F4P6 ARM-Cortex M0 proces ...
- After 2 years, I have finally solved my "Slow Hyper-V Guest Network Performance" issue. I am ecstatic.
Edit - It should be known that I was initially researching this issue back in 2012 and the solution ...
- Android: INSTALL_FAILED_UPDATE_INCOMPATIBLE错误解决措施
晚上在测一个widget,前面测的好好的,后面再安装的时候发现如下错误:[2009-06-07 02:39:35 - battery] Performing sync[2009-06-07 02:39 ...
- 在ASP.NET MVC中使用Castle Windsor
平常用Inject比较多,今天接触到了Castle Windsor.本篇就来体验其在ASP.NET MVC中的应用过程. Visual Studio 2012创建一个ASP.NET MVC 4网站. ...