jQuery旋转插件jqueryrotate

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 做演示,图片如下,请注意对比,不要看花眼了。

Google Chrome

演示1 直接旋转一个角度

Google Chrome

1
$('#img1').rotate(45);

1
$('#img1').rotate({angle:45});

演示2 鼠标移动效果

Google Chrome

1
2
3
4
5
6
7
8
9
$('#img2').rotate({
    bind : {
        mouseover : function(){
            $(this).rotate({animateTo: 180});
        }, mouseout : function(){
            $(this).rotate({animateTo: 0});
        }
    }
});

演示3 不停旋转

Google Chrome

1
2
3
4
5
var angle = 0;
setInterval(function(){
    angle +=3;
    $('#img3').rotate(angle);
}, 50);

Google Chrome

1
2
3
4
5
6
7
8
var rotation = function (){
    $('#img4').rotate({
        angle: 0,
        animateTo: 360,
        callback: rotation
    });
}
rotation();

Google Chrome

1
2
3
4
5
6
7
8
9
10
11
var rotation2 = function(){
    $('#img5').rotate({
        angle: 0,
        animateTo: 360,
        callback: rotation2,
        easing: function(x,t,b,c,d){
            return c*(t/d)+b;
        }
    });
}
rotation2();

演示4 点击旋转

Google Chrome

1
2
3
4
5
6
7
8
9
10
11
$('#img6').rotate({
    bind: {
        click: function(){
            $(this).rotate({
                angle: 0,
                animateTo: 180,
                easing: $.easing.easeInOutExpo
            });
        }
    }
});

Google Chrome

1
2
3
4
5
6
7
8
9
10
11
var value2 = 0;
$('#img7').rotate({
    bind: {
        click: function(){
            value2 +=90;
            $(this).rotate({
                animateTo: value2
            });
        }
    }
});

参数

参数 类型 说明 默认值
angle 数字 旋转一个角度 0
animateTo 数字 从当前的角度旋转到多少度 0
step 函数 每个动画步骤中执行的回调函数,当前角度值作为该函数的第一个参数
easing 函数 自定义旋转速度、旋转效果,需要使用 jQuery.easing.js
callback 函数 旋转完成后的回调函数
getRotateAngle 函数 返回旋转对象当前的角度
stopRotate 函数 停止旋转