Spin image onclick Javascript

Like the title says, I am trying to rotate an image once a user clicks a button. I am new to javasript so I am still trying to figure out how things work. I have found a good example but the two images they have are always spinning. I want my image to just spin once for 45 degrees. I want the image to spin like the ones here: http://jsfiddle.net/Pvtzv/276/ but not everytime just once Here is what I have so far: function doSpin() { wheel = new Image(); //wheel.onload = initialDraw; // Once the image is loaded from file this function is called to draw the image in its starting position. wheel.src = "./female_avatar.gif"; var surfaceContext = surface.getContext('2d'); surfaceContext.drawImage(wheel, 0, 0); p += .02; var r = 100; var xcenter = 150; var ycenter = 150; var newLeft = Math.floor(xcenter + (r* Math.cos(p))); var newTop = Math.floor(ycenter + (r * Math.sin(p))); var newLeft1 = Math.floor(xcenter + -(r* Math.cos(p))); var newTop1 = Math.floor(ycenter + -(r * Math.sin(p))); wheel.animate({ top: newTop, left: newLeft, }, 2, function() { doSpin() }); } In my html

以上就是Spin image onclick Javascript的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准