javascriptは画像の回転を制御します.
2197 ワード
//IE
function ieTrans(o,d){
o.style.fileter=d
}
// IE
function notieTrans(o,d){
o.style.MozTransform = d;
o.style.webkitTransform = d;
o.style.msTransform = d;
o.style.OTransform = d;
o.style.transform = d;
}
//
function rightRotate(){
var o=$('mainImg');
if(Browser.name=='ie'){//IE
var currentFilter = o.currentStyle.filter;
if (currentFilter){
var filterMatch = currentFilter.match(/rotation=(\d)+/);
var r = parseInt(filterMatch[1]) + 1;
if(r > 3) r = 0;
ieTrans(o,'progid:DXImageTransform.Microsoft.BasicImage(rotation=' + r + ')');
}else{
ieTrans(o,'progid:DXImageTransform.Microsoft.BasicImage(rotation=1)');
}
}else{// IE
var currentFilter = o.style.MozTransform;
//console.log(currentFilter);
if (currentFilter){ //
var filterMatch = currentFilter.match(/rotate\(([\-]?\d+)deg\)/);
var r = parseInt(filterMatch[1]) + 90;
if (r > 0) r = -270;
console.log('rotate(' + r + 'deg)');
notieTrans(o,'rotate(' + r + 'deg)');
}else{
// o.style.MozTransform , , 90 ,-270
console.log('rotate(-270deg)');
notieTrans(o,'rotate(-270deg)');
}
}
}
//
function leftRotate(){
var o=document.getElementById('mainImg');
if(window.attachEvent){//IE
var currentFilter = o.currentStyle.filter;
if (currentFilter){
var filterMatch = currentFilter.match(/rotation=(\d)+/);
var r = parseInt(filterMatch[1]) - 1;
if(r < 0) r = 3;
ieTrans(o,'progid:DXImageTransform.Microsoft.BasicImage(rotation=' + r + ')');
}
}else{// IE
var currentFilter = o.style.MozTransform;
//console.log(currentFilter);
if (currentFilter){
console.log(currentFilter);
var filterMatch = currentFilter.match(/rotate\(([\-]?\d+)deg\)/);
var r = parseInt(filterMatch[1]) - 90;
if (r > 270) r = 0;
notieTrans(o,'rotate(' + r + 'deg)');
}else{
notieTrans(o,'rotate(270deg)');
}
}
}