基于jquery的3d效果實(shí)現(xiàn)代碼
更新時(shí)間:2011年03月23日 22:20:16 作者:
基于jquery的3d效果實(shí)現(xiàn)代碼,需要的朋友可以參考下。
復(fù)制代碼 代碼如下:
<html>
<head>
<script type="text/javascript" src="http://demo.jb51.net/jslib/jquery/jquery-1.4.2.min.js"></script><style>
.s_c{
position:relative;
width:800px;
height:300px;
border:1px solid #000;
overflow:hidden;
}
</style>
<script type="text/javascript">
var Sl=Sl||{};
(function(){
var undefined;
function box(o){
var d=$.extend({},{
'w':40,
'h':30,
'secne':null,
'data':''
},o);
if(d.secne==null||!d.secne) return;
this.div=$("<div></div>").css({'position': 'absolute','border':'1px solid #cde','left':'0px','top':'0px'}).html(d.data);
this.w(d.w);
this.h(d.h);
this._ow=this.w();
this._oh=this.h();
$(d.secne).append(this.div);
return this;
}
box.prototype.zoomw=function(v){
if(v==undefined){
this._zw=this._zw||1;
return this._zw;
}
this.w(this.ow()*v,false);
this._zw=v;
return this;
}
box.prototype.zoomh=function(v){
if(v==undefined){
this._zh==this._zh||1;
return this._zh;
}
this.h(this.oh()*v,false);
this._zh=v;
return this;
}
box.prototype.x=function(x){
if(x==undefined){
this._x=this._x||0;
return this._x;
}
this.div.css({
left:x-(this.w())/2
})
this._x=x;
return this;
}
box.prototype.y=function(y){
if(y==undefined){
this._y=this._y||0;
return this._y;
}
this.div.css({
top:y-(this.h())/2
})
this._y=y;
return this;
}
box.prototype.ow=function(){
return this._ow||0;
}
box.prototype.oh=function(){
return this._oh||0;
}
box.prototype.w=function(w,rs){
if(w==undefined){
w=this.div.css('width');
w=w=='auto'?this.div.width():w;
return parseInt(w);
}
if(rs!==false)
this._ow=w;
this.mx(-(w-this.w())/2);
this.div.css({'width':w});
return this;
}
box.prototype.h=function(h,rs){
if(h==undefined){
h=this.div.css('height');
h=h=='auto'?this.div.height():h;
return parseInt(h);
}
if(rs!==false)
this._oh=h;
this.my(-(h-this.h())/2);
this.div.css({'height':h});
return this;
}
box.prototype.mx=function(x){
var div=this.div;
div.css({'left': parseInt(div.css('left'))+x});
}
box.prototype.my=function(y){
var div=this.div;
div.css({'top':parseInt(div.css('top'))+y});
}
box.prototype.z=function(z){
if(z==undefined)
return this.div.css('z-index');
this.div.css("z-index",z);
return this;
}
//3d box
function box3d(o){
if(!$(o.secne))return;
secne=o.secne;
var secne=this.secne=$(secne);
this.vx= parseInt(secne.css('width')=='auto'?secne.width():secne.css('width'))/2;
this.vy= parseInt(secne.css('height')=='auto'?secne.height():secne.css('height'))/2;
this.fl=o.fl||250;
this.box=new box(o).z(0);
this._set3d();
return this;
}
box3d.prototype.x=function(x){
if(x==undefined)
return this._x||0;
this._x=x||0;
this._set3d();
return this;
}
box3d.prototype.y=function(y){
if(y==undefined)
return this._y||0;
this._y=y||0;
this._set3d();
return this;
}
box3d.prototype.z=function(z){
if(z==undefined)
return this._z||0;
this._z=z||0;
this._set3d();
return this;
}
box3d.prototype._set3d=function(){
var boxo=this.box;
var fl=this.fl;
var zomx=fl/(fl+this.z());
var x=this.vx+zomx*this.x();
var y=this.vy+zomx*this.y();
boxo.zoomw(zomx).zoomh(zomx);
boxo.x(x);
boxo.y(y);
}
//
function slide(o){
var d=$.extend({},{
'z':100,
'secne':null
},o);
if(d.secne==null||!$(d.secne))return;
this.cecne=d.secne;
this.z=d.z;
this.sleep=0.02;
var k={'secne':d.secne,'w':80,'h':50,fl:1000};
this.box=[];
var c=8;
for(var i=0;i<c;i++){
var t= parseInt(i-c/2);
var a=$('<div></div>').css({
width:'100%',
height:'100%',
background:'#777'
})
k.data=a;
var ubox=new box3d(k).z(300);
this.r(ubox,t/2);
this.box.push(ubox);
}
this.re_index();
}
slide.prototype._moveaction=function(){
var _this=this;
var s=this.sleep;
for(var i=0;i<this.box.length;i++){
this.r(this.box[i],s);
}
this.re_index();
}
slide.prototype.r=function(rbox,s){
if(!(rbox instanceof box3d))
return;
var X=rbox.x();
var Y=rbox.y()
var Z=rbox.z();
var New_X = X*Math.cos(s) - Z*Math.sin(s);
var New_Z = X*Math.sin(s) + Z*Math.cos(s);
var New_Y = Y;
rbox.x(New_X);
rbox.y(New_Y);
rbox.z(New_Z);
}
slide.prototype.re_index=function(){
var arr=this.box;
var s=arr.length;
for(var j=0;j<s-1;j++){
for(var i=0;i<s-j-1;i++){
if(arr[i].z()<arr[i+1].z()){
var c=arr[i];
arr[i]=arr[i+1];
arr[i+1]=c;
}
}
}
for(var i=0;i<arr.length;i++){
arr[i].box.z(i)
}
}
slide.prototype.start=function(){
this.run=1;
this._move();
}
slide.prototype.stop=function(){
this.run=0;
}
slide.prototype._move=function(s){
var _this=this;
setTimeout(function(){
if(!_this.run){
return;
}
_this._moveaction();
_this._move();
},50)
}
Sl.slide=slide;
})()
$(function(){
var s=new Sl.slide({secne:'.s_c'});
$('#start').click(function(){s.start()})
$('#stop').click(function(){s.stop()})
})
</script>
</head>
<body>
<div class='s_c'></div>
<button id="start">start</button>
<button id="stop">stop</button>
</body>
</html>
您可能感興趣的文章:
- jQuery實(shí)現(xiàn)鼠標(biāo)懸停3d菜單展開動(dòng)畫效果
- jquery+CSS3實(shí)現(xiàn)3D拖拽相冊(cè)效果
- 酷炫jQuery全屏3D焦點(diǎn)圖動(dòng)畫效果
- jQuery+CSS3實(shí)現(xiàn)3D立方體旋轉(zhuǎn)效果
- jquery實(shí)現(xiàn)的3D旋轉(zhuǎn)木馬特效代碼分享
- jquery實(shí)現(xiàn)疊層3D文字特效代碼分享
- jQuery實(shí)現(xiàn)3D文字特效的方法
- jQuery實(shí)現(xiàn)圖像旋轉(zhuǎn)動(dòng)畫效果
- jQuery實(shí)現(xiàn)的產(chǎn)品自動(dòng)360度旋轉(zhuǎn)展示特效源碼分享
- jQuery實(shí)現(xiàn)炫麗的3d旋轉(zhuǎn)星空效果
相關(guān)文章
Jquery 過濾器(first,last,not,even,odd)的使用
Jquery 過濾器,顧名思義就是過濾一些不需要的元素,主要有first,last,not,even,odd等等,下面有個(gè)使用示例,大家可以感受下2014-01-01
CSS3 media queries結(jié)合jQuery實(shí)現(xiàn)響應(yīng)式導(dǎo)航
這篇文章主要為大家詳細(xì)介紹了CSS3 media queries結(jié)合jQuery實(shí)現(xiàn)響應(yīng)式導(dǎo)航,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09
JQuery記住用戶名密碼實(shí)現(xiàn)下次自動(dòng)登錄功能
這篇文章主要介紹了JQuery記住用戶名密碼實(shí)現(xiàn)下次自動(dòng)登錄功能,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-04-04
jquery實(shí)現(xiàn)的可隱藏重現(xiàn)的靠邊懸浮層實(shí)例代碼
本實(shí)例使用jquery操作div的CSS實(shí)現(xiàn)了可隱藏重現(xiàn)的靠邊懸浮層,具體實(shí)現(xiàn)代碼如下,感興趣的朋友可以參考下哈2013-05-05
jQuery實(shí)用小技巧_輸入框文字獲取和失去焦點(diǎn)的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)?lái)一篇jQuery實(shí)用小技巧_輸入框文字獲取和失去焦點(diǎn)的簡(jiǎn)單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2016-08-08
jQuery實(shí)現(xiàn)的導(dǎo)航動(dòng)畫效果(附demo源碼)
這篇文章主要介紹了jQuery實(shí)現(xiàn)的導(dǎo)航動(dòng)畫效果,可實(shí)現(xiàn)導(dǎo)航條的底部橫條隨鼠標(biāo)移動(dòng)的效果,涉及jQuery針對(duì)鼠標(biāo)事件的響應(yīng)及頁(yè)面元素樣式動(dòng)態(tài)變換的相關(guān)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2016-04-04

