如何使用 jquery 和 CSS3 KeyFrames 将元素(例如 div 或图像)围绕点或鼠标圈出?
我在尝试使用 jquery 和 css3 关键帧来移动或围绕点或鼠标周围移动或环绕元素(例如 div 或图像)时
遇到了问题,而不是延迟时间,只是保持环绕。
有什么解决办法吗?请让我看看。提前致谢 !
all
i have a problem in trying to using jquery and css3 keyframe to move or circle an element such as div or image around a point or mouse continues, not delay time, just keep circle around.
Any solution ? please show me. thanks in advance !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从您的澄清评论来看:
CSS3 动画
要制作围绕某个点平滑旋转元素并永远持续的动画,您可以使用这些 CSS3 关键帧/动画和 2D 转换属性:
animation
指定时间和关键帧使用。动画计时函数
指定您想要平滑的动画(线性
)。@keyframes
准确指定如何制作动画元素。transform-origin
绕 div 中心以外的点旋转(一些偏移)。transform
移动元素从旋转中心(轨道半径)出来。旋转(<角度>);
< /a> 指定您要在关键帧中旋转。您可能需要复制这些内容并在每个前面加上
-webkit-
、-moz-
和-ms-
一段时间,直到 CSS3 动画功能得到广泛支持。在 CSS/jQuery 中指定位置
您可以使用普通的 CSS 围绕任意点旋转 HTML 元素:
如果您希望持续将动画集中在鼠标光标上,则需要使用 jQuery 来处理 mousemove 文档上的事件,并设置元素 CSS 的
left
和top
属性。类似于:
文档
.mousemove
处理程序方法.css
setter 方法代码示例
我已经构建了一个代码示例来研究您需要的函数和参考自己构建这个。由于其他答案已经为您提供了他们的代码示例,因此我将继续发布我的代码示例。
我强烈建议你自己构建这个,这样你可以了解这些东西是如何工作的:)
浏览器支持
请参阅此页面包含 CSS3 动画支持矩阵,和 此页面包含 CSS3 2D 变换支持矩阵。
要点是:
-o-
转换标签以使其工作,但动画支持尚不存在)From your clarifying comments:
CSS3 Animation
To make an animation where you rotate an element around a point smoothly and continue forever, you can use these CSS3 keyframe/animation and 2D transformation properties:
animation
to specify timing and which keyframes to use.animation-timing-function
to specify that you want a smooth animation (linear
).@keyframes
to specify exactly how to animate the element.transform-origin
to rotate around a point other than the center of the div (some offset).transform
to move the element out from the center of rotation (radius of orbit).rotate(<angle>);
to specify that you want to rotate in your keyframe(s).You will probably need to duplicate these and prefix each with
-webkit-
,-moz-
and-ms-
for a while until the CSS3 animation features are widely supported.Specifying position in CSS/jQuery
You can use plain-old CSS to rotate an HTML element around an arbitrary point:
If you want to continually center your animation on the mouse cursor, you'll need to use jQuery to handle the
mousemove
event on the document, and set theleft
andtop
properties of the element's CSS.Something like:
Docs
.mousemove
handler method.css
setter methodCode Sample
I had built a code sample to research the functions and references you'd need to build this on your own. Since the other answer already gave you their code sample, I'll go ahead and post mine.
I highly recommend you build this out yourself so you can learn how these things work :)
Browser Support
See this page with a CSS3 Animation support matrix, and this page with a CSS3 2D Transform support matrix.
The gist is:
-o-
Tranform tags to make it work, and the Animation support just isn't there yet)我认为这就是您所要求的: http://jsfiddle.net/BZSQd/
如果有,请告诉我你有任何问题吗:)
I think this is what you were asking for: http://jsfiddle.net/BZSQd/
Let me know if you have any questions :)