我正在尝试制作一个非常基本的HTML5/jQuery旋转脚本。代码如下:
$(document).find("[data-rot]").each(function(i, e) {
var rotation = $(this).attr("data-rot");
console.log(i+' '+rotation);
$(this).css({ '-moz-transform': rotation, '-webkit-transform': rotation });
});和HTML:
<div data-rot="90">Rotate me 90 degrees</div>
<div data-rot="20">Rotate me 20 degrees</div>
<div data-rot="180">Rotate me 180 degrees</div>
<div data-rot="300">Rotate me 300 degrees</div>我做错了什么?console.log()起作用了。
发布于 2011-10-10 02:09:04
尝试将transform属性的值设置为rotate(90deg),而不仅仅是一个数字,依此类推。除了旋转之外,还有更多的CSS转换函数,请参阅更多here。
发布于 2011-10-10 02:12:05
用法:$(this).css({ '-moz-transform': rotation+"deg", '-webkit-transform': rotation+"deg"})
基本上,您需要将旋转设置为"xdeg",而不是"x“。
https://stackoverflow.com/questions/7705436
复制相似问题