CSS3 提供了多种变形效果,好比矩阵变形、位移、缩放、旋转和倾斜等等,让页面更加生动活泼有趣,再也不一动不动。而后 IE10 如下版本的浏览器不支持 CSS3 变形,虽然 IE 有私有属性滤镜(filter),但不全面,并且效果和性能都很差。javascript
今天介绍一款 jQuery 插件——jqueryrotate,它能够实现旋转效果。jqueryrotate 支持全部主流浏览器,包括 IE6。若是你想在低版本的 IE 中实现旋转效果,那么 jqueryrotate 是一个很好的选择。
兼容性html
jqueryrotate 支持全部主流浏览器,包括 IE6。jqueryrotate 在高级浏览器中使用 CSS3 transform 属性实现,在低版本 IE 中使用 VML 实现。固然,你可使用 IE 条件注释,低版本 IE 使用 jqueryrotate,高级浏览器则直接使用 CSS3。html5
参数 | 类型 | 说明 | 默认值 |
---|---|---|---|
angle | 数字 | 旋转一个角度 | 0 |
animateTo | 数字 | 从当前的角度旋转到多少度 | 0 |
step | 函数 | 每一个动画步骤中执行的回调函数,当前角度值做为该函数的第一个参数 | 无 |
easing | 函数 | 自定义旋转速度、旋转效果,须要使用 jQuery.easing.js | 无 |
callback | 函数 | 旋转完成后的回调函数 | 无 |
getRotateAngle | 函数 | 返回旋转对象当前的角度 | 无 |
stopRotate | 函数 | 中止旋转 | 无 |
演示虽然使用的是图片,但 jqueryrotate 并不仅是能运用在图片上,其余元素如 div 等也可使用。同时,你能够发挥想象,制做出更多关于旋转的特效。java
<!doctype html> <html> <head> <meta charset="utf-8"> <title>jQuery旋转插件jqueryrotate</title> <style> /* * ease-in-out 规定以慢速开始和结束的过渡效果 */ img{ -moz-transition: all 0.2s ease-in-out; -webkit-transition: all 0.2s ease-in-out; -o-transition: all 0.2s ease-in-out; -ms-transition: all 0.2s ease-in-out; transition: all 0.2s ease-in-out; } img:hover{ -moz-transform: rotate(70deg); -webkit-transform: rotate(70deg); -o-transform: rotate(70deg); -ms-transform: rotate(70deg); transform: rotate(70deg); } body{background: url(images/bg.jpg) repeat center center;} .test { width: 500px; height: 300px; margin: 30px auto; position: relative; } .test img { position: absolute; top: 40%; left: 0%; margin-left: -70px; margin-top: -100px; } .test img:nth-child(1){ z-index: 1; opacity: .6; } .test img:nth-child(2){ z-index: 2; transform: rotate(45deg); } </style> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="js/jquery.rotate.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ //旋转45度 $('#img1').rotate({angle:45}); //鼠标滑过旋转180,离开回0度 $("#img2").rotate({ bind: { mouseover : function() { $(this).rotate({animateTo:180}); }, mouseout : function() { $(this).rotate({animateTo:0}); } } }); //慢速旋转 var angle = 0; setInterval(function(){ angle+=3; $("#img3").rotate(angle); },50); //快速旋转一周,callback回调有时间间隔 var rotation = function (){ $("#img4").rotate({ angle:0, animateTo:360, callback: rotation }); } rotation(); //这个没搞明白怎么用 var rotation2 = function (){ $("#img5").rotate({ angle:0, animateTo:360, callback: rotation2, easing: function (x,t,b,c,d){ // t: current time, b: begInnIng value, c: change In value, d: duration return c*(t/d)+b; } }); } rotation2(); //点击后旋转180度 $("#img6").rotate({ bind: { click: function(){ $(this).rotate({ angle:0,animateTo:180,easing: $.easing.easeInOutExpo }) } } }); //每次点击在原基础上旋转90度 var value2 = 0 $("#img7").rotate({ bind: { click: function(){ value2 +=90; $(this).rotate({ animateTo:value2}) } } }); //跷跷板动画 var nnn = 0; setInterval(function(){ nnn++; if(nnn>=20){ $("#img8").rotate(45); } if(nnn>=50){ $("#img8").rotate(0); nnn=0; } },50); }); </script> </head> <body> <img id="img1" src="images/chrome.png" width="256" height="256"/> <img id="img2" src="images/chrome.png" width="256" height="256" /> <img id="img3" src="images/chrome.png" width="256" height="256"/> <img id="img4" src="images/chrome.png" width="256" height="256"/> <br> <img id="img5" src="images/chrome.png" width="256" height="256"/> <img id="img6" src="images/chrome.png" width="256" height="256"/> <img id="img7" src="images/chrome.png" width="256" height="256"/> <img id="img8" src="images/chrome.png" width="256" height="256"/> <br>鼠标滑事后旋转,离开后恢复原位: <div class="test"> <img src="images/cardKingClub.png" alt="" width="70" height="100" /> <a herf="#"><img src="images/cardKingClub.png" alt="" width="70" height="100" /></a> </div> <div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';"> html5网页动画总结--jQuery旋转插件jqueryrotate </div> </body> </html>