javascript - 是否可以有一个不断旋转的 DIV 或图像?

标签 javascript html css

我想要一个图像或 DIV 在点击时开始旋转,类似于电唱机。是否有可能让它顺利并使用 javascript?

非常感谢您! :)

最佳答案

您必须在 CSS3 中进行旋转。

@keyframes rotate
{
     0%   { transform: rotate(0); }
     25%  { transform: rotate(90); }
     50%  { transform: rotate(180); }
     75%  { transform: rotate(270); }
     100% { transform: rotate(360); }
}

#rotating_div
{
    animation-name: rotate;
    animation-duration: 4s;
    animation-iteration-count: infinite;
    animation-play-state: paused;
}

这是 JavaScript:

function rotate(id) {
    div = getElementById['id'];
    div.style.animation-play-state = running;
}

这是 HTML:

<div id="rotating_div" onclick="rotate("rotating_div")"></div>

使用前缀 -moz- 和 -webkit- 让 CSS3 在 FF 和其他浏览器中工作。在这里看看:W3Schools.com

祝你好运! :)

关于javascript - 是否可以有一个不断旋转的 DIV 或图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8200507/

相关文章:

javascript - 使用另一个单选按钮启用单选按钮

javascript - 将图像更改为内联 SVG >> 以获得所有 SVG 功能

javascript - JavaScript 中的占位符未运行

css - IE9 渲染 CSS 表的方式与 Chrome 不同

javascript - 自动向上滚动移动网站体验

css - 骨架和列数

javascript - 在 iOS 9 Safari 上打开 Bootstrap 模式时屏幕放大

javascript - 在javascript中刷新页面时阻止变量的更改值

html - 如何预加载 svg Sprite ?

html - 我怎样才能在浏览器之间始终将 css 居中?