本文實(shí)例講述了jQuery旋轉(zhuǎn)插件jqueryrotate用法。分享給大家供大家參考,具體如下:

根河網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,根河網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為根河千余家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站制作要多少錢(qián),請(qǐng)找那個(gè)售后服務(wù)好的根河做網(wǎng)站的公司定做!
CSS3
提供了多種變形效果,比如矩陣變形、位移、縮放、旋轉(zhuǎn)和傾斜等等,讓頁(yè)面更加生動(dòng)活潑有趣,不再一動(dòng)不動(dòng)。然后
IE10
以下版本的瀏覽器不支持
CSS3
變形,雖然
IE
有私有屬性濾鏡(filter),但不全面,而且效果和性能都不好。
今天介紹一款
jQuery
插件——jqueryrotate,它可以實(shí)現(xiàn)旋轉(zhuǎn)效果。jqueryrotate
支持所有主流瀏覽器,包括
IE6。如果你想在低版本的
IE
中實(shí)現(xiàn)旋轉(zhuǎn)效果,那么
jqueryrotate
是一個(gè)很好的選擇。
兼容性
jqueryrotate
支持所有主流瀏覽器,包括
IE6。jqueryrotate
在高級(jí)瀏覽器中使用
CSS3
transform
屬性實(shí)現(xiàn),在低版本
IE
中使用
VML
實(shí)現(xiàn)。當(dāng)然,你可以使用
IE
條件注釋,低版本
IE
使用
jqueryrotate,高級(jí)瀏覽器則直接使用
CSS3。
使用方法
//演示1
//旋轉(zhuǎn)45angle
$(document.body).click(function
()
{
//方式1
$('.divOne').rotate(45);
//方式2
$('.divOne').rotate({
angle:
45
});
});
//演示2
//鼠標(biāo)移動(dòng)效果
//方式1
$('.divOne').rotate({
bind:
{
mouseover:
function
()
{
$(this).rotate({
animateTo:
180
});
},
mouseout:
function
()
{
$(this).rotate({
animateTo:
});
}
}
});
//方式2
$('.divOne').mouseover(function
()
{
$(this).rotate({
animateTo:
180
});
}).mouseout(function
()
{
$(this).rotate({animateTo:0});
});
//演示3
不停旋轉(zhuǎn)
//方式1
var
angle
=
0;
setInterval(function
()
{
angle
+=
3;
$('.divOne').rotate(angle);
},
50);
//方式2
var
rotation
=
function
()
{
$('.divOne').rotate({
angle:
0,
animateTo:
360,
callback:rotation
})
}
rotation();
//方式3
var
rotation
=
function
()
{
$('.divOne').rotate({
angle:
0,
animateTo:
360,
callback:
rotation,
easing:
function
(x,
t,
b,
c,
d)
{
return
c
*
(t
/
d)
+
b;
}
})
}
rotation();
//演示4
點(diǎn)擊旋轉(zhuǎn)
//方式1
$('.divOne').click(function
()
{
$(this).rotate({
angle:
0,
animateTo:
180,
easing:
$.easing.easeInOutExpo
});
});
var
val
=
0;
$('.divOne').click(function
()
{
val
+=
90;
$(this).rotate({
animateTo:
val
});
});
參數(shù)
參數(shù)
類型
說(shuō)明
默認(rèn)值
angle
數(shù)字
旋轉(zhuǎn)一個(gè)角度
animateTo
數(shù)字
從當(dāng)前的角度旋轉(zhuǎn)到多少度
step
函數(shù)
每個(gè)動(dòng)畫(huà)步驟中執(zhí)行的回調(diào)函數(shù),當(dāng)前角度值作為該函數(shù)的第一個(gè)參數(shù)
無(wú)
easing
函數(shù)
自定義旋轉(zhuǎn)速度、旋轉(zhuǎn)效果,需要使用
jQuery.easing.js
無(wú)
duration
整數(shù)
旋轉(zhuǎn)持續(xù)時(shí)間,以毫秒為單位
callback
函數(shù)
旋轉(zhuǎn)完成后的回調(diào)函數(shù)
無(wú)
getRotateAngle
函數(shù)
返回旋轉(zhuǎn)對(duì)象當(dāng)前的角度
無(wú)
stopRotate
函數(shù)
停止旋轉(zhuǎn)
無(wú)
演示雖然使用的是圖片,但
jqueryrotate
并不只是能運(yùn)用在圖片上,其他元素如
div
等也可以使用。同時(shí),你可以發(fā)揮想象,制作出更多關(guān)于旋轉(zhuǎn)的特效。
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery窗口操作技巧總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jquery中Ajax用法總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常見(jiàn)經(jīng)典特效匯總》、《jQuery動(dòng)畫(huà)與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head
meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
titleJS 旋轉(zhuǎn)函數(shù),兼容各個(gè)瀏覽器/title
script id="jscode"
function hy_rotate(obj, rotate){
if(obj){
function rotate_set_style(obj, key, value){
obj.style[key] = value;
}
function rotate_float(n, b){
b = isNaN(parseInt(b)) ? -1 : parseInt(b);
return isNaN(parseFloat(n)) ? 0 : (b == 0) ? parseInt(parseFloat(n)) : (b 0) ? parseFloat(parseFloat(n).toString().replace((new RegExp('^(\\d+)\\.(\\d{'+b+'})\\d*$')), '$1.$2')) : parseFloat(n);
}
rotate = rotate % 360;
if(rotate 0){
rotate = 360 + rotate
}
rotate = rotate_float(rotate, 2);
var rpi = rotate * Math.PI / 180, c = Math.cos(rpi), s = Math.sin(rpi), oh = obj.offsetHeight, ow = obj.offsetWidth, pw = rotate_float((oh * Math.abs(s) + ow * Math.abs(c)), 2), ph = rotate_float((oh * Math.abs(c) + ow * Math.abs(s)), 2), tw = (rotate % 180 == 0) ? 0 : ((pw - ow) / 2), th = (rotate % 180 == 0) ? 0 : ((ph - oh) / 2), css3 = 'translate(' + tw + 'px, ' + th + 'px) rotate(' + rotate + 'deg)', css3key = '', dbstyle = document.body.style, css3keys = ['transform', '-moz-transform', '-webkit-transform', '-o-transform', '-ms-transform'];
for(var i in css3keys){
if(css3keys[i] in dbstyle){
css3key = css3keys[i];
}
}
if(css3key == ''){
rotate_set_style(obj, 'filter', 'progid:DXImageTransform.Microsoft.Matrix(M11=' + c + ', M12=' + (-s) + ', M21=' + s + ', M22=' + c + ', sizingMethod=\'auto expand\')');
}else{
obj.parentNode.style.width = pw + 'px';
obj.parentNode.style.height = ph + 'px';
rotate_set_style(obj, css3key, css3);
}
}
}
/script
style
.list{clear:both; padding:20px;}
.block{background:#FF99FF; padding:5px; float:left;}
.rotate{background:#FF0000; width:200px; padding:5px;}
.txt{background:#3366FF; padding:10px; color:#FFFFFF; font-size:12px; margin-bottom:10px;}
.code{border:#3333FF dotted 1px; padding:10px; background:#FFCCFF; clear:both;}
/style
/head
body
divJS 旋轉(zhuǎn)函數(shù),兼容各個(gè)瀏覽器/div
div class="list"
div class="block"
div
div class="rotate" id="rotate"
div class="txt"
我的角度是 span id="rotate_num"/span°
/div
img src="" /
/div
/div
/div
/div
script
function $id(id){
return document.getElementById(id);
}
var rrr = 0;
var sss = 0;
var iii = 0;
var aaa = $id('rotate');
var bbb = $id('rotate_num');
function zzz(){
rrr = rrr+1;
bbb.innerHTML = rrr;
hy_rotate(aaa, rrr);
}
aaa.onclick = function(){
if(sss == 0){
iii = setInterval(zzz, 20);;
sss = 1;
}else{
clearInterval(iii);
sss = 0;
}
}
/script
/body
/html
rotate這只是一個(gè)對(duì)jquery擴(kuò)充的插件而已,你沒(méi)有那個(gè)插件你寫(xiě)這個(gè)參數(shù)是無(wú)效的。你可以去下載rotate這個(gè)插件,要不你就用css3寫(xiě)如下:
$('#test').animate({??borderSpacing:?-90?},?{????step:?function(now,fx)?{
$(this).css('-webkit-transform','rotate('+now+'deg)');??????
$(this).css('-moz-transform','rotate('+now+'deg)');??????
$(this).css('-ms-transform','rotate('+now+'deg)');
$(this).css('-o-transform','rotate('+now+'deg)');??????
$(this).css('transform','rotate('+now+'deg)');??????},
duration:'slow'?},'linear');
js和jquery做不到的,首先這個(gè)是css3中的3d轉(zhuǎn)換,用到transform:rotateX(50deg)?,只不過(guò)是旋轉(zhuǎn)中心要在你畫(huà)的線中間,設(shè)置transform-origin:50%?0;?(這里是xy軸,可以理解為集合第四項(xiàng)現(xiàn),所以旋轉(zhuǎn)軸所在位置就是紅色箭頭位置的坐標(biāo),x和-y)
整理代碼:
div{?width:500px;?height:500px;?background:#333;?transform-origin:50%?0;?transform:rotateX(50deg);
如有疑問(wèn)歡迎咨詢
可以通過(guò)addClass()方法來(lái)代替此動(dòng)作:
比如想旋轉(zhuǎn)一個(gè)icon:
在css中加入一個(gè)class
[css]?view plain?copy
.add_transform{
transform:rotate(180deg);
-ms-transform:rotate(180deg);????/*?IE?9?*/
-moz-transform:rotate(180deg);???/*?Firefox?*/
-webkit-transform:rotate(180deg);?/*?Safari?和?Chrome?*/
-o-transform:rotate(180deg);????/*?Opera?*/
transition:?all?0.5s?ease-in-out;
-moz-transition:?all?0.5s?ease-in-out;?/*?Firefox?4?*/
-webkit-transition:?all?0.5s?ease-in-out;?/*?Safari?和?Chrome?*/
-o-transition:?all?0.5s?ease-in-out;?/*?Opera?*/
}
然后通過(guò)$("選擇器").toggleClass(".add_transform");來(lái)使icon的旋轉(zhuǎn)變?yōu)閯?dòng)畫(huà)效果。
或者下載補(bǔ)丁(加一個(gè)js文件):
用css吧,CSS就行的,例如:
順時(shí)針旋轉(zhuǎn)90度:
-moz-transform:rotate(90deg);
-webkit-transform:rotate(90deg);
-o-transform:rotate(90deg);
transform:rotate(90deg);
filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=1);
其它度數(shù)請(qǐng)自行修改下,可以用在LOGO之類的Hover效果,360度的話,參考下:
p
img{
-moz-transition:
all
0.8s
ease-in-out;
-webkit-transition:
all
0.8s
ease-in-out;
-o-transition:
all
0.8s
ease-in-out;
-ms-transition:
all
0.8s
ease-in-out;
transition:
all
0.8s
ease-in-out;
}
p
img:hover{
-moz-transform:
rotate(360deg);
-webkit-transform:
rotate(360deg);
-o-transform:
rotate(360deg);
-ms-transform:
rotate(360deg);
transform:
rotate(360deg);
}
/*繞Z軸的*/
img{
-webkit-transition:
0.4s;
-webkit-transition:
-webkit-transform
0.4s
ease-out;
transition:
transform
0.4s
ease-out;
-moz-transition:
-moz-transform
0.4s
ease-out;
}
img:hover{
transform:
rotateZ(360deg);
-webkit-transform:
rotateZ(360deg);
-moz-transform:
rotateZ(360deg);
}
網(wǎng)站標(biāo)題:jquery旋轉(zhuǎn)效果,jquery 折疊
文章網(wǎng)址:http://chinadenli.net/article11/dsgocdd.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、搜索引擎優(yōu)化、網(wǎng)站設(shè)計(jì)公司、網(wǎng)站改版、、網(wǎng)站排名
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)