java 图片绕中心旋转_如何围绕图像中心旋转 Span ?

我有一个带图像的画布:

p3MV4.png

在图片的右侧,您可以看到一个带有刷新图标的白色正方形,有点被黑色圆圈隐藏 . 我创建了这样的:

var rotatorSpan = document.createElement("span");

rotatorSpan.id = _this.idRotator;

rotatorSpan.className = "glyphicons glyphicons-restart";

document.getElementById("canvas-overlay").appendChild(rotatorSpan);

在我的绘图功能:

this.drawRotator = function() {

var pivotX = _this.x + (_this.imageWidth / 2);

var pivotY = _this.y + (_this.imageHeight / 2);

var radius = Math.sqrt(Math.pow((_this.x - pivotX), 2) + Math.pow((_this.y - pivotY), 2));

var rotatorX = _this.x + (_this.imageWidth / 2) + radius;

var rotatorY = _this.y + (_this.imageHeight / 2) + (_this.indicatorRadius / 2);

_this.ctx.save();

_this.ctx.translate(pivotX, pivotY);

_this.ctx.rotate(_this.rotation);

_this.ctx.translate(-pivotX, -pivotY);

_this.ctx.beginPath();

_this.ctx.arc(rotatorX, rotatorY, this.indicatorRadius, 0, Math.PI * 2, false);

_this.ctx.closePath();

_this.ctx.fill();

_this.ctx.restore();

document.getElementById(_this.idRotator).style.position = "absolute";

document.getElementById(_this.idRotator).style.top = rotatorY + "px";

document.getElementById(_this.idRotator).style.left = rotatorX + "px";

document.getElementById(_this.idRotator).style.fontSize = "1em";

document.getElementById(_this.idRotator).style.backgroundColor = "#fff";

document.getElementById(_this.idRotator).style.border = "1px solid #000;";

document.getElementById(_this.idRotator).style.zIndex = 1000;

document.getElementById(_this.idRotator).style.transform = "rotate(" + _this.rotation + "rad)";

};

现在当我旋转我的照片时:

72nON.png

你可以看到一切都在旋转,除了带有刷新图标的白色方块 . 它只围绕自己的中心点旋转 .

The Question

如何围绕图像的中心点旋转白色方块(我创建的 Span 元素)?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值