html5 canvas写一个图片围绕图片中心一直旋转的代码,用translate和rotate方法 30

html5canvas写一个图片围绕图片中心一直旋转的代码,用translate和rotate方法... html5 canvas写一个图片围绕图片中心一直旋转的代码,用translate和rotate方法 展开
 我来答
xinyu11290124
2015-07-20 · TA获得超过281个赞
知道小有建树答主
回答量:110
采纳率:0%
帮助的人:73.4万
展开全部
一定要用canvas吗?这里给你一个代码,看看能不能参考一下,有必要你模仿着改成canvas咯。

上代码(图片自己找一张):

<html>
<head>
<style>
#rotate_img {
margin: 100px;
}
</style>
</head>
<body>
<button onclick="rotate()">开始旋转</button>
<button onclick="pause()">暂停旋转</button>
<!--这里自己找张图片,路径写对就行-->
<img src='photo.jpg' id='rotate_img'/>
</body>
</html>

<script>
<!--
var x, n=0, rotINT;
function rotate() {
x = document.getElementById("rotate_img");
clearInterval(rotINT);
rotINT = setInterval("startRotate()",10);
}

function pause () {
clearInterval(rotINT);
}

function startRotate() {
n = n + 1;
x.style.transform = "rotate(" + n + "deg)";
x.style.webkitTransform = "rotate(" + n + "deg)";
x.style.OTransform = "rotate(" + n + "deg)";
x.style.MozTransform = "rotate(" + n + "deg)";
if (n == 180 || n == 360) {
if (n >= 360){
n = 0;
}
}
}

//-->
</script>
追问
亲,谢谢你,但不是我想要的,HTML5的CANVAS不像CSS3那样简单的
追答
嗯,抱歉没帮到你。以前我也很喜欢canvas,后来慢慢接触移动web app,感觉很多东西没必要用canvas。那你在百度上搜一下,应该很多现成的。
来自:求助得到的回答
旺理财
2015-07-20 · 百度知道合伙人官方认证企业
旺理财
1、AA级以上公募债券理财产品 2、短期理财产品【3天收益12%、1个月7.5%、3个月8.2%、6个月8.8%】 3、应用市场搜索“旺理财”下载APP理财
向TA提问
展开全部
<!DOCTYPE html>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>canvas</title>
<script type="text/javascript">
function fly(){
var myImage=document.getElementById("myCanvas");
var cxt = myImage.getContext("2d");
var img = new Image();
img.src="http://www.baidu.com/img/bd_logo1.png";

//执行旋转的特效
function spfly(){
cxt.drawImage(img,400,700);
cxt.translate(-80,60); //中心点
cxt.rotate(-0.1);
//clearInterval(timer);
}
var timer =setInterval(spfly,60);
}
</script>
</head>

<body >
<section >
<button onClick=" fly();">开始</button>
<canvas id="myCanvas" width="1300" height="1000">

</canvas>
<section>
</body>
</html>
这样就可以了

document.getElementByIdx_x_x 是自定义方法
改成js的document.getElementById就好了
然后图片路径也要对
追问
不是这个效果,是围绕图片中心点转哦
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2015-07-20
展开全部
<!DOCTYPE html>
<html lang="en">
<head>
<meta content="text/plain" charset="UTF-8">
<title>Document</title>
</head>
<body>
<canvas id="myCanvas" width="400" height="400" style="border:1px solid blue">
Your browser does not support the canvas element.
</canvas>
</body>
<script>
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
c.width=400; //画板大小
c.height=400;
var img=new Image();
img.src="b7e6ce04.jpg";//要加载的图片
ctx.translate(200,200);//重设中心点
t=window.setInterval(function(){
ctx.clearRect(-200,-200,600,600);//清除之前
ctx.rotate(5*Math.PI/180);//旋转角度
ctx.drawImage(img,-80,-80);//绘制图片 设置好图片中心点
},1000);//旋转速度
</script>
</html>
追问
亲,图片并没有围绕图片中心点转哦
追答
ctx.translate(200,200); 
ctx.drawImage(img,-80,-80);
数据设置问题 计算下该镇么填
方法是没问题的 我测试了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
海南岛也会下雪
2017-07-07 · TA获得超过317个赞
知道小有建树答主
回答量:312
采纳率:74%
帮助的人:66.7万
展开全部
你只要将div换成img就行了
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
div{
width: 200px;
height: 200px;
background: yellow;
animation:myfirst 5s linear 2s infinite alternate;
-webkit-animation:myfirst 5s linear 0s infinite normal;
-moz-animation: myfirst 5s linear 0s infinite normal;
-o-animation: myfirst 5s linear 0s infinite normal;
}

@keyframes myfirst{
0%{
transform: rotate(0deg);
}
100%{
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<div style=""></div>
</body>
</html>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式