使用javascript旋转图像
Rotate images with javascript
我可以用javascript旋转li项吗?
我有一个脚本。它将随机的li项以固定的位置放在页面上。但是我可以给这li项一个旋转吗?我想让每件物品再旋转一次。我怎样才能给这八个项目一个固定的位置呢?
这是我的脚本:
var images = [];
// Constructor for the "Position" structure
function Position(left, top) {
this.left=left;
this.top=top;
}
// sortFunction routine to help randomize array
function rand(ar){
return 0.5-Math.random();
}
// Array containing the 8 positions you want to use
var positionArray = [
new Position(0, 0)
, new Position(50, 50)
, new Position(100,100)
, new Position(150,150)
, new Position(200,200)
, new Position(250,250)
, new Position(300,300)
, new Position(350,350)
];
function init() {
$('.friend-selection li > div').each(function(){
var id = this.id;
var img = $('#img_' + id);
var imageIndex = parseInt(id.substring(id.length - 1))-1; // This is a hack because you're using "picture*" as the id
$("#parent_" + id).css({ //apply the position to parent divs
top : positionArray[imageIndex].top,
left : positionArray[imageIndex].left
});
});
};
// Randomize array - http://stackoverflow.com/questions/7802661
positionArray.sort(rand);
init();
function rotate(object, degrees) {
object.css({
'-webkit-transform' : 'rotate('+degrees+'deg)',
'-moz-transform' : 'rotate('+degrees+'deg)',
'-ms-transform' : 'rotate('+degrees+'deg)',
'-o-transform' : 'rotate('+degrees+'deg)',
'transform' : 'rotate('+degrees+'deg)',
'zoom' : 1
});
}
调用该函数,例如:
rotate($("#image1"), 15)
jsfiddle: http://jsfiddle.net/hLqJb/
CSS3具有旋转可用性,但并非适用于所有浏览器。如果你不依赖于浏览器特定的功能,你可以使用它。
-webkit-transform: rotate(15deg);
-moz-transform:rotate(15deg);
-o-transform:rotate(15deg);
-ms-transform:rotate(15deg);
transform:rotate(15deg);
翻译成jQuery,应该很好去
相关文章:
- 需要关于随机图像旋转的指南
- Jquery CSS背景图像旋转
- 全屏背景图像+旋转图像
- 随机图像旋转的多个实例
- JS下拉菜单显示在图像旋转器上
- 请解释Javascript图像旋转代码
- JavaScript 中的图像旋转器(键下)
- jquery 图像旋转器(仅在 JS 中传递图像)
- 如何停止多次单击下一个以破坏我的图像旋转器
- 停止 3 个图像旋转只需单击一个按钮
- 背景图像旋转器.php + jQuery每4秒显示一次随机照片
- 图像旋转背景 js 跳转到页面顶部
- 画布图像旋转中的问题
- 在画布上绘制多个图像,每个图像旋转
- 使用关键帧图像旋转器时,图像不会在两个块之间同步协调
- 最简单的图像旋转器 - 使用设置间隔失败
- 需要按钮显示/隐藏图像旋转 href 添加到 javascript 代码中
- 图像旋转和Jcrop.js
- 360 度图像旋转指示器
- 通过手机加载时,画布图像会将图像旋转 90 度