/*任意(yì)位(wèi)置浮动固定层(céng)*/ /*没剑(http://regedit.cnblogs.com) 08-03-11*/ /*说明:可以让指定的层浮动到网页(yè)上的(de)任(rèn)何位置,当滚动条滚动时它(tā)会保持在当前(qián)位置不(bú)变,不会产(chǎn)生闪动*/ /*2008-4-1修改:当自定义(yì)right位置(zhì)时无(wú)效(xiào),这里加上一个(gè)判断 有值时就(jiù)不设置,无值(zhí)时要加18px已修正层(céng)位置在ie6下(xià)的问题 */ /*调用: 1 无参数调用(yòng):默认浮动(dòng)在(zài)右下角(jiǎo) $("#id").floatdiv(); 2 内置固(gù)定位置(zhì)浮动 //右下角 $("#id").floatdiv("rightbottom"); //左下角 $("#id").floatdiv("leftbottom"); //右下角(jiǎo) $("#id").floatdiv("rightbottom"); //左(zuǒ)上(shàng)角 $("#id").floatdiv("lefttop"); //右上角 $("#id").floatdiv("righttop"); //居中(zhōng) $("#id").floatdiv("middle"); 3 自定义位置浮动 $("#id").floatdiv({left:"10px",top:"10px"}); 以上(shàng)参数(shù),设置(zhì)浮动层(céng)在(zài)left 10个像素,top 10个像素的位置 */ jQuery.fn.floatdiv=function(locations){ //ie6要隐藏纵向滚动条(tiáo) var isIE6=false; if($.browser.msie && $.browser.version=="6.0"){ $("html").css("overflow-x","auto").css("overflow-y","hidden"); isIE6=true; }; $("body").css({margin:"0px",padding:"0 10px 0 10px", border:"0px", height:"100%", overflow:"auto" }); return this.each(function(){ var loc;//层的绝对定位(wèi)位置 if(locations==undefined || locations.constructor == String){ switch(locations){ case("rightbottom")://右下角(jiǎo) loc={right:"0px",bottom:"0px"}; break; case("leftbottom")://左(zuǒ)下角 loc={left:"0px",bottom:"0px"}; break; case("lefttop")://左上角(jiǎo) loc={left:"0px",top:"0px"}; break; case("righttop")://右上(shàng)角 loc={right:"0px",top:"0px"}; break; case("middle")://居中 var l=0;//居(jū)左 var t=0;//居(jū)上 var windowWidth,windowHeight;//窗口的高(gāo)和宽(kuān) //取得窗口的高和宽 if (self.innerHeight) { windowWidth=self.innerWidth; windowHeight=self.innerHeight; }else if (document.documentElement&&document.documentElement.clientHeight) { windowWidth=document.documentElement.clientWidth; windowHeight=document.documentElement.clientHeight; } else if (document.body) { windowWidth=document.body.clientWidth; windowHeight=document.body.clientHeight; } l=windowWidth/2-$(this).width()/2; t=windowHeight/2-$(this).height()/2; loc={left:l+"px",top:t+"px"}; break; default://默认为右下(xià)角 loc={right:"0px",bottom:"0px"}; break; } }else{ loc=locations; } $(this).css("z-index","9999").css(loc).css("position","fixed"); if(isIE6){ if(loc.right!=undefined){ //2008-4-1修改:当(dāng)自定义right位置时(shí)无效,这里加上一个判断(duàn) //有值(zhí)时就不设(shè)置,无值(zhí)时(shí)要加18px已修正(zhèng)层位置 if($(this).css("right")==null || $(this).css("right")==""){ $(this).css("right","18px"); } } $(this).css("position","absolute"); } }); };