jqueryrotate:可以改变旋转点吗? (变换画布函数)

发布于 2024-10-17 07:06:06 字数 480 浏览 2 评论 0原文

我正在尝试通过使用 jquery roate 插件旋转图像来制作动画。 不幸的是,这个插件不会改变它的旋转点,它总是居中的。 并且它没有为此的参数

我发现使用画布执行此操作我可以使用 canvas.transform() 函数设置它。

我是使用画布的初学者,但如果有人能给我一个如何做到这一点的例子,我将非常感激。

这是图像旋转插件: http://wilq32.adobeair.pl/jQueryRotate/Wilq32.jQueryRotate .html

这里是用画布制作的..(但有点糟糕,因为它留下了痕迹。不知道为什么 http://jsbin.com/ipeqi3/2

I'm trying to do an amimation by rotating an image with the jquery roate plugin.
Unfortunately this plugin doesn't change it's point of rotation it's always centered..
and it doesn't have a parameter for this

I've found that doing this with canvas I can set it with canvas.transform() function.

I'm a begginer on working with canvas, but if somebody can give me an example how to do this I will greatly apreciate it.

here's the image rotate plugin: http://wilq32.adobeair.pl/jQueryRotate/Wilq32.jQueryRotate.html

here's made with canvas..(but kind of bad because it leaves trails.don't know why http://jsbin.com/ipeqi3/2)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独夜无伴 2024-10-24 07:06:06

这就是我到目前为止所拥有的,实际上它通过平移改变旋转点来旋转图像(不是变换,我的错......)

它不做的事情它不会创建平滑的动画,它非常粗糙。 .我怎样才能做到这一点?

我需要的另一件事是背景必须是透明的,

这是到目前为止我的代码:

<script>
var degree=10;

function docanvas() {
     var canvas = document.getElementById('canvas');
var cContext = canvas.getContext('2d');

 var img = new Image();   
  // Create new Image object     
  img.src = 'http://www.gravatar.com/avatar/e555bd971bc2f4910893cd5b785c30ff?s=128&d=identicon&r=PG'; // Set source path // set img src 


var cw = img.width, ch = img.height, cx = 0, cy = 0;


canvas.setAttribute('width', 300);
canvas.setAttribute('height', 300);

cContext.fillStyle = "rgba(0, 0, 255, .5)";
cContext.fillRect(0, 0, 300, 300);

cContext.translate(150, 150);


cContext.rotate(degree * Math.PI / 180);
cContext.drawImage(img, -64, -128,128,128);

    degree+=5;

}
</script>


</head>
<body onload="setInterval('docanvas()',50);">
<canvas id="canvas"></canvas>
<script>
       docanvas(30);
</script>       
</body>
</html>

This is what I have so far, indeed it rotates the image by changing the point of rotation with translate (not transform, my bad...)

What It DOESN'T do it doesn't create a smooth animation, it's very rough..How can I accomplish that?

Another thing I need is that the background HAS to be transparent

here's my code so far:

<script>
var degree=10;

function docanvas() {
     var canvas = document.getElementById('canvas');
var cContext = canvas.getContext('2d');

 var img = new Image();   
  // Create new Image object     
  img.src = 'http://www.gravatar.com/avatar/e555bd971bc2f4910893cd5b785c30ff?s=128&d=identicon&r=PG'; // Set source path // set img src 


var cw = img.width, ch = img.height, cx = 0, cy = 0;


canvas.setAttribute('width', 300);
canvas.setAttribute('height', 300);

cContext.fillStyle = "rgba(0, 0, 255, .5)";
cContext.fillRect(0, 0, 300, 300);

cContext.translate(150, 150);


cContext.rotate(degree * Math.PI / 180);
cContext.drawImage(img, -64, -128,128,128);

    degree+=5;

}
</script>


</head>
<body onload="setInterval('docanvas()',50);">
<canvas id="canvas"></canvas>
<script>
       docanvas(30);
</script>       
</body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文