旋转画布仅在第一次有效
我试图在每次鼠标悬停时旋转画布,但它只是第一次工作。
你可以在这里玩一下: http://jsfiddle.net/h3Z7j/2/
我的原因将其旋转 0 度是为了在加载时将其转换为画布,因为我是第一次加载 img
。
旋转脚本:http:// code.google.com/p/jquery-rotate/downloads/detail?name=jquery.rotate.1-1.js
<div class="gameboard">
<img width="40" height="40" id="1-1" src="http://www.netbsd.org/images/download-icon-orange.png" alt="">
<img width="40" height="40" id="2-1" src="http://www.netbsd.org/images/download-icon-orange.png" alt="">
<img width="40" height="40" id="1-2" src="http://www.netbsd.org/images/download-icon-orange.png" alt="">
<img width="40" height="40" id="2-2" src="http://www.netbsd.org/images/download-icon-orange.png" alt="">
</div>
$(document).ready(function () {
$(".gameboard img").each(function () {
$(this).rotateLeft(0);
});
$(".gameboard canvas").mouseover(function () {
$(this).rotateLeft();
});
});
编辑
如果有其他更好的轮换脚本,我会很乐意更改为该脚本。
I'm trying to rotate a canvas on every mouseover, but it's only working the first time.
You can play with it here: http://jsfiddle.net/h3Z7j/2/
The reason I'm rotating it 0 degrees is to convert it to canvases on load, since I'm loading img
's the first time.
rotation script: http://code.google.com/p/jquery-rotate/downloads/detail?name=jquery.rotate.1-1.js
<div class="gameboard">
<img width="40" height="40" id="1-1" src="http://www.netbsd.org/images/download-icon-orange.png" alt="">
<img width="40" height="40" id="2-1" src="http://www.netbsd.org/images/download-icon-orange.png" alt="">
<img width="40" height="40" id="1-2" src="http://www.netbsd.org/images/download-icon-orange.png" alt="">
<img width="40" height="40" id="2-2" src="http://www.netbsd.org/images/download-icon-orange.png" alt="">
</div>
$(document).ready(function () {
$(".gameboard img").each(function () {
$(this).rotateLeft(0);
});
$(".gameboard canvas").mouseover(function () {
$(this).rotateLeft();
});
});
edit
If there are other rotation scripts that work better I'll happily change to that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基于 Rory 的答案,您可以通过在 mouseover/mouseout 上将标志设置为 true/false 来实现每次鼠标悬停旋转一圈:
请参阅: http: //jsfiddle.net/CK5hh/
Building on Rory's answer you can achieve one spin per mouseover by setting a flag to true/false on mouseover/mouseout:
See: http://jsfiddle.net/CK5hh/
问题是因为
canvas
元素被删除,然后读取到 DOM。然后,这将丢失放置在其上的mouseover
处理程序。如果您使用delegate
附加事件,它会起作用:虽然我不确定效果是否正是您想要的:)
小提琴示例
The problem is because the
canvas
element is being removed, and then readded to the DOM. This is then losing themouseover
handler placed on it. If you attach your event withdelegate
instead, it works:Although I'm not sure the effect is exactly what you're after :)
Example fiddle