基于jquery的3d效果实现代码_jquery
程序员文章站
2022-04-25 10:02:02
...
复制代码 代码如下:
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
var a=$('').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.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
arr[i]=arr[i+1];
arr[i+1]=c;
}
}
}
for(var i=0;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()})
})
推荐阅读
-
jquery创建并行对象或者合并对象的实现代码
-
jQuery插件FusionCharts实现的3D帕累托图效果示例【附demo源码】
-
基于jquery实现发送文章到手机的代码分享
-
jQuery基于事件控制实现点击显示内容下拉效果
-
jQuery插件FusionCharts实现的2D面积图效果示例【附demo源码下载】
-
基于jQuery实现无缝轮播与左右点击效果
-
jQuery插件HighCharts实现的2D面积图效果示例【附demo源码下载】
-
jQuery animate()实现背景色渐变效果的处理方法【使用jQuery.color.js插件】
-
jQuery插件HighCharts实现的2D条状图效果示例【附demo源码下载】
-
jquery 实现密码框的显示与隐藏示例代码