CSS3 提供了多种变形效果,比如矩阵变形、位移、缩放、旋转和倾斜等等,让页面更加生动活泼有趣,不再一动不动。然后 IE10 以下版本的浏览器不支持 CSS3 变形,虽然 IE 有私有属性滤镜(filter),但不全面,而且效果和性能都不好。
今天介绍一款 jQuery 插件——jqueryrotate,它可以实现旋转效果。jqueryrotate 支持所有主流浏览器,包括 IE6。如果你想在低版本的 IE 中实现旋转效果,那么 jqueryrotate 是一个很好的选择。
兼容性jqueryrotate 支持所有主流浏览器,包括 IE6。jqueryrotate 在高级浏览器中使用 CSS3 transform 属性实现,在低版本 IE 中使用 VML 实现。当然,你可以使用 IE 条件注释,低版本 IE 使用 jqueryrotate,高级浏览器则直接使用 CSS3。
使用方法我们使用 Google Chrome 的 Logo 做演示,图片如下,请注意对比,不要看花眼了。
- $('#img1').rotate(45);
或
- $('#img1').rotate({angle:45});
- $('#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);
- 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){
- return c*(t/d)+b;
- }
- });
- }
- rotation2();
- $('#img6').rotate({
- bind: {
- click: function(){
- $(this).rotate({
- angle: 0,
- animateTo: 180,
- easing: $.easing.easeInOutExpo
- });
- }
- }
- });
- var value2 = 0;
- $('#img7').rotate({
- bind: {
- click: function(){
- value2 +=90;
- $(this).rotate({
- animateTo: value2
- });
- }
- }
- });
演示虽然使用的是图片,但 jqueryrotate 并不只是能运用在图片上,其他元素如 div 等也可以使用。同时,你可以发挥想象,制作出更多关于旋转的特效。