|
|
Line 79: |
Line 79: |
| var e=this.elem.style; | | var e=this.elem.style; |
| this.from=(b===undefined?(parseFloat(e.opacity)):b); | | this.from=(b===undefined?(parseFloat(e.opacity)):b); |
- | d=d||{};
| |
- | this.duration=d.duration||500;
| |
- | this.frameRate=d.frameRate||30;
| |
- | this.onFinish=d.onFinish;
| |
- | this.totalFrames=Math.ceil(this.duration/1000*this.frameRate);
| |
- | this.perFrame=(this.to-this.from)/this.totalFrames;
| |
- | this.frameNb=0;var f=this;
| |
- | this.next=function(){
| |
- | this.prog=setTimeout(function(){f.frame()},1000/this.frameRate)};
| |
- | this.frame=function(){
| |
- | p(this.elem,this.from+this.perFrame*this.frameNb);
| |
- | if(this.frameNb===this.totalFrames){
| |
- | p(this.elem,this.to);
| |
- | if(typeof this.onFinish=='function'){
| |
- | setTimeout(this.onFinish,1)
| |
- | }
| |
- | }else{
| |
- | this.frameNb++;
| |
- | this.next()}};
| |
- | this.next()}function A(c,a,b){
| |
- | var d,e,f,j,k,l,i,g,h;
| |
- | b=b||{};
| |
- | d=b.max_w;
| |
- | e=b.min_w;
| |
- | f=b.max_h;
| |
- | j=b.max_h;
| |
- | k=b.round===undefined?1:b.round;
| |
- | l=c/a;
| |
- | i=a/c;
| |
- | g=a;
| |
- | h=c;
| |
- | if(h<e){
| |
- | h=e;
| |
- | g=h*i
| |
- | }
| |
- | if(g<j){
| |
- | g=j;
| |
- | h=g*l
| |
- | }
| |
- | if(d&&(h>d)){
| |
- | h=d;
| |
- | g=h*i
| |
- | }
| |
- | if(f&&(g>f)){
| |
- | g=f;
| |
- | h=g*l
| |
- | }
| |
- | h=h<0?0:h;
| |
- | g=g<0?0:g;
| |
- | return{w:k?Math.round(h):h,h:k?Math.round(g):g}
| |
- | }
| |
- | var q={
| |
- | defaults:{
| |
- | mode:'max',
| |
- | enlarge:1,
| |
- | reduce:1,
| |
- | ffHack:0,
| |
- | zIndex:-1,
| |
- | position:'absolute',
| |
- | align:'center',
| |
- | vertAlign:'top',
| |
- | fadeAfter:400,
| |
- | fadeOptions:{duration:1000,frameRate:25}
| |
- | },
| |
- | redim:function(){
| |
- | var c=q,a,b,d=w(),e,f,j,k,l,i,g,h,m,n;
| |
- | a=c.img;f=j=k=l='';
| |
- | b=c.opt;
| |
- | i=a.fileDim;
| |
- | if(i){
| |
- | if(b.mode=='full'){
| |
- | g=m=d.w;
| |
- | h=n=d.h;
| |
- | if(!b.enlarge){
| |
- | if(g>i.w){
| |
- | g=m=i.w
| |
- | }
| |
- | if(h>i.h){
| |
- | h=n=i.h
| |
- | }
| |
- | }
| |
- | if(!b.reduce){
| |
- | if(m<i.w){
| |
- | m=i.w;
| |
- | g=Math.max(m,g)
| |
- | }
| |
- | if(n<i.h){
| |
- | n=i.h;
| |
- | h=Math.max(n,h)
| |
- | }
| |
- | }
| |
- | }else{
| |
- | m=g=d.w;
| |
- | n=h=0;
| |
- | if(!b.reduce){
| |
- | g=0
| |
- | }
| |
- | }
| |
- | i=A(i.w,i.h,{min_w:m,win_h:n,max_w:g,max_h:h,round:1});
| |
- | a.width=i.w;
| |
- | a.height=i.h;
| |
- | if(!a.width){
| |
- | a.removeAttribute("width")
| |
- | }
| |
- | if(!a.height){
| |
- | a.removeAttribute("height")
| |
- | }
| |
- | switch(b.align){
| |
- | case'left':k='0px';
| |
- | break;
| |
- | case'right':l='0px';
| |
- | break;
| |
- | default:k=-Math.round((i.w-d.w)/2)+'px'
| |
- | }
| |
- | if(b.vertAlign=='bottom'){
| |
- | j='0px'
| |
- | }else if(b.vertAlign=='middle'){
| |
- | e=b.position=="fixed"?d.h:x().h;
| |
- | f=(-b.ffHack+(e-a.offsetHeight)/2)+"px"
| |
- | }else{
| |
- | f=a.hack||'0px'
| |
- | }
| |
- | s(a,{left:k,right:l,top:f,bottom:j})
| |
- | }
| |
- | }
| |
- | ,show:function(){
| |
- | var c=q,a;
| |
- | a=c.img;
| |
- | a.fileDim={
| |
- | w:a.naturalWidth||a.clientWidth,h:a.naturalHeight||a.clientHeight
| |
- | };
| |
- | c.redim();
| |
- | if(c.fadeIt){
| |
- | z(c.img,1,0,c.opt.fadeOptions)
| |
- | }else{
| |
- | p(a,1)
| |
- | }
| |
- | },
| |
- | init:function(c,a){
| |
- | var b=q,d=v('body')[0],e,f,j;
| |
- | a=u(a,this.defaults);
| |
- | if(t&&t<7){
| |
- | a.position='absolute'
| |
- | }
| |
- | b.opt=a;
| |
- | e=a.fadeAfter;
| |
- | f=b.img=o.createElement('img');
| |
- | f.id="bgMax";
| |
- | s(f,{zIndex:a.zIndex,position:a.position});
| |
- | j=navigator.userAgent.match(/Firefox.(\d+(\.\d+))/);
| |
- | if(j&&parseFloat(j[1])<3){
| |
- | s(d,{zIndex:0,position:'relative',top:0,left:0});
| |
- | f.hack='-'+a.ffHack}d.insertBefore(f,d.childNodes[0]);
| |
- | f.onload=b.show;
| |
- | if(e!==false){
| |
- | p(f,0);
| |
- | if(e){
| |
- | setTimeout(function(){b.fadeIt=1},e)
| |
- | }else{
| |
- | b.fadeIt=1
| |
- | }
| |
- | }
| |
- | y(r,'resize',b.redim);
| |
- | f.src=c
| |
- | }
| |
- | };
| |
- | r.bgMax=q
| |
- | })
| |
- | (window,document);
| |
- | alert("coucou");
| |
- |
| |
| } | | } |
| | | |