基于jquery的3d效果实现代码_jquery

复制代码 代码如下:

<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>

时间: 2024-08-02 04:57:07

基于jquery的3d效果实现代码_jquery的相关文章

基于jquery的loading效果实现代码_jquery

在代码<head></head>里加入以下代码: <script type="text/javascript" src="jquery.js"></script><script type="text/javascript">$(window).load(function(){$("#loading").hide();})</script> 在里<bo

基于jQuery实现返回顶部实例代码_jquery

效果图展示如下所示: 使用方法: 只需引用jQuery库和YesTop插件,然后一句代码就可以实现返回顶部: 引用代码: <script type="text/javascript" src="http://hovertree.com/ziyuan/jquery/jquery-1.11.3.min.js"></script> <script type="text/javascript" src="http:

基于JQuery的多标签实现代码_jquery

今天要分享的是基于JQuery实现的多标签的切换,JQuery就不用过多介绍了,网上一搜一大堆资料,当然这样的小示例也有很多,这里只是发表一些自己的想法. 下面是本次示例所使用的HTML页面: 复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html xmlns="http://ww

jquery实现手风琴效果实例代码_jquery

复制代码 代码如下: //jquery实现手风琴效果  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  <html xmlns="http://www.w3.org/1999/xhtml">  <head>  <

基于JQuery的密码强度验证代码_jquery

    因为是基于JQuery的控件,当然需要JQuery库,还要一个本控件的JS.JQuery的JS大家可以到官网下载:http://code.jquery.com/jquery-1.4.2.min.js 这个控件的JS文件:password_strength_plugin.js password_strength_plugin.js 复制代码 代码如下: (function($){ $.fn.shortPass = 'Too short'; $.fn.badPass = 'Weak'; $.

基于JQuery的Pager分页器实现代码_jquery

实例效果图如下 使用说明 需要使用jQuery库文件和JQuery Pager库文件(目前版本1.1) 素材准备 分页器CSS样式文件,可复制如下CSS样式,可命名为Pager.css 复制代码 代码如下: #pager ul.pages { display:block; border:none; text-transform:uppercase; font-size:10px; margin:10px 0 50px; padding:0; } #pager ul.pages li { list

jquery div拖动效果示例代码_jquery

复制代码 代码如下: <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-

autoIMG 基于jquery的图片自适应插件代码_jquery

为了防止图片撑破布局,最常见的仍然是通过onload后获取图片尺寸再进行调整,所以加载过程中仍然会撑破.而Qzone日志的图片在此进行了改进,onload完毕后才显示原图.我以前用onload写过一个小例子:http://www.planeart.cn/?p=1022 通过imgReady可以跨浏览器在dom ready就可以实现图片自适应,无需等待img加载,代码如下: 复制代码 代码如下: // jQuery.autoIMG.js v0.2 // Tang Bin - http://plan

基于jquery的滑动样例代码_jquery

复制代码 代码如下: <html> <head> <title>here</title> <script src="http://code.jquery.com/jquery-1.4.4.min.js"></script> </head> <body style="text-align: center;"> <div style="width:540px;