JQuery 旋转 - 在镶边中重新启动旋转
JQuery rotate - re-initiate rotation in chrome
我有一个圆形图像,它在页面加载时旋转,并在鼠标悬停/悬停时停止和开始。 圆圈也是可拖动的,以便我可以手动旋转它。 这一切都在Mozilla中运行良好,但在Chrome中效果不佳。 问题是它不会在鼠标退出时重新启动rotateCircle();
。 谁能帮忙找出为什么会这样? 我为此使用jQueryRotate
和Greensock Draggable
。
$(function() {
var angle = 0;
var int;
rotateCircle();
function rotateCircle() {
int = setInterval(function() {
angle += 3;
$("#circle").rotate(angle);
}, 100);
}
$("#circle").mouseover(function() {
clearInterval(int);
Draggable.create("#circle", {type:"rotation",throwProps:true});
}).mouseout(function() {
rotateCircle();
});
});
</script>
一种更简单的方法是将 rotateBy 方法添加到 GreenSock Draggable 类中。
下面是更新的可拖动类:https://raw.githubusercontent.com/furqanZafar/GreenSock-JS/master/src/uncompressed/utils/Draggable.js
我只在 Draggable 中添加了以下方法.js:
this.rotateBy = function(amount) {
self.rotation += amount;
self.x = self.rotation;
dirty = true;
render();
}
以下是使用新的 Draggable 类在 chrome 和 ff 上运行的 jsfiddle:http://jsfiddle.net/58rauhsL/
$(function() {
var draggable = Draggable.create("#circle", {type:"rotation",throwProps:true}),
interval;
function rotateCircle() {
interval = setInterval(function() {
draggable[0].rotateBy(3);
}, 100);
}
rotateCircle();
$("#circle").mouseover(function() {
clearInterval(interval);
}).mouseout(function() {
rotateCircle();
});
});
我不太明白为什么需要Javascript?
http://jsfiddle.net/nmmkLpqo/(仅针对 chrome 的示例,为 FX 添加供应商前缀等)
img {
border-radius: 50%;
-webkit-animation: rotation 5s linear infinite;
}
img:hover {
-webkit-animation-play-state: paused;
}
@-webkit-keyframes rotation {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}
这应该完全一样吗?
相关文章:
- 当我在重新启动cordova应用程序后尝试添加更多数据时,lokijs会丢失数据库和收集中的数据
- 重新启动jquery脚本后,角度停止工作
- Chrome内容脚本制作cookie;chrome重新启动时,cookie会被删除.如何使其稳定
- preventDefault之后的重新启动事件
- WebStorm,使用Node Supervisor(因此不必在每次代码更改后重新启动)
- 重新启动游戏jQuery功能不工作
- Web服务器意外退出,正在重新启动新实例
- 在变量中保存值的最佳方法是在应用程序关闭后使用,然后使用apachecordova在android中重新启动
- 重新启动画布 JavaScript
- 事件侦听器,用于完全关闭后重新启动的应用程序
- Node SocketIO以编程方式强制在损坏的套接字上重新启动
- 服务器重新启动后javascript不工作
- 当滚动到指定的位置时,启动功能,如何重置它并重新启动,如果我们再次回到这个位置
- Gulp Concat+Browsesync重新启动
- 在 javaScript 中重新启动 setInterval
- 如何为Sails.js创建启动/停止/重新启动Linux服务
- 如何暂停和重新启动jquery数据表插件
- 如何创建一个onclick函数,该函数在按下重新启动按钮时被调用
- 在第一次安装扩展时,使用Javascript重新启动Google Chrome
- JQuery 旋转 - 在镶边中重新启动旋转