javascript实现DIV图片旋转

//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)');   }   } }
返回顶部
跳到底部

Copyright 2011-2024 南京追名网络科技有限公司 苏ICP备2023031119号-6 乌徒帮 All Rights Reserved Powered by Z-BlogPHP Theme By open开发

请先 登录 再评论,若不是会员请先 注册