JQuery Position Plugin _jquery

Source: Internet
Author: User
Plug-in code:
* * Any position floating fixed layer
* * No Sword (http://regedit.cnblogs.com) 08-03-11*/
/* Description: You can allow the specified layer to float to any location on the page, when the scroll bar scrolling it will remain unchanged in the current position, does not produce flashing * *
/*2008-4-1 modification: Invalid when customizing right position, here plus a judgment
When there is a value is not set, no value to add 18px has been corrected layer position under the IE6 problem
*/
/* Call:
1 NO parameter call: Default float in lower right corner
$ ("#id"). Floatdiv ();
2 Built-in fixed position float
Lower right corner
$ ("#id"). Floatdiv ("Rightbottom");
Lower left corner
$ ("#id"). Floatdiv ("Leftbottom");
Lower right corner
$ ("#id"). Floatdiv ("Rightbottom");
Upper left corner
$ ("#id"). Floatdiv ("Lefttop");
Top right corner
$ ("#id"). Floatdiv ("Righttop");
Center
$ ("#id"). Floatdiv ("Middle");
3 Custom Position Float
$ ("#id"). Floatdiv ({left: ' 10px ', Top: "10px"});
The above parameters, set the floating layer in the left 10 pixels, top 10 pixel position
*/
Jquery.fn.floatdiv=function (location) {
IE6 to hide the vertical scroll bar
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 () {
Absolute location of Var loc;//layer
if (location==undefined | | location.constructor = = String) {
Switch (location) {
Case ("Rightbottom")://Lower right corner
Loc={right: "0px", Bottom: "0px"};
Break
Case ("Leftbottom")://Lower left corner
Loc={left: "0px", Bottom: "0px"};
Break
Case ("Lefttop")://upper left corner
Loc={left: "0px", Top: "0px"};
Break
Case ("Righttop")://upper right corner
Loc={right: "0px", Top: "0px"};
Break
Case ("Middle")://Center
var l=0;//left
var t=0;//reside on
The height and width of the var windowwidth,windowheight;//window
Get the height and width of the window
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://defaults to lower right corner
Loc={right: "0px", Bottom: "0px"};
Break
}
}else{
Loc=location;
}
$ (this). CSS ("Z-index", "9999"). CSS (loc). CSS ("position", "fixed");
if (isIE6) {
if (loc.right!=undefined) {
2008-4-1 modified: Invalid when customizing right position, plus a judgment
When there is a value is not set, no value to add 18px has been corrected layer position
if ($ (this). css (' right ') ==null | | $ (this). CSS ("right") = = "") {
$ (this). CSS ("Right", "18px");
}
}
$ (this). CSS ("position", "absolute");
}
});
};
How to use:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<title> Floating window plugin at any location </title>
<script type= "Text/javascript" src= ". /js/jquery-1.2.6.js "></script>
<script type= "Text/javascript" src= ". /js/jquery.floatdiv.js "></script>
<script type= "Text/javascript" >
$ (function () {
$ ("#test"). Floatdiv ({top: "200px", Right: "200px"});
$ ("#rtop"). Floatdiv ("Righttop");
$ ("#floatAd"). Floatdiv ({top: "50px", Left: "50px"});
});
</script>

<body>
<div id= "Rtop" style= "Background-color: #666633; width:300px; Height:100px;padding:2px;color:white; " > Top Right corner </div>
<div id= "Floatad" style= "Background-color: #667733; width:300px; Height:100px;padding:2px;color:white; " > Lower left corner </div>
<div id= "test" style= "Background-color: #665533; width:300px; Height:100px;padding:2px;color:white; " >
<p>
/* Any position floating fixed layer */<br/>
/* Description: You can allow the specified layer to float to any location on the page, when the scroll bar scrolls it will remain unchanged at the current position, does not produce a flashing */<br/>
/* Call: <br/>
1 NO parameter call: Default float in lower right corner <br/>
$ ("#id"). Floatdiv ();</p>
<p>
2 built-in fixed position floating <br/>
Lower right corner <br/>
$ ("#id"). Floatdiv ("Rightbottom"); <br/>
Left Lower corner <br/>
$ ("#id"). Floatdiv ("Leftbottom"); <br/>
Lower right corner <br/>
$ ("#id"). Floatdiv ("Rightbottom"); <br/>
Upper left corner <br/>
$ ("#id"). Floatdiv ("Lefttop"); <br/>
Top right corner <br/>
$ ("#id"). Floatdiv ("Righttop"); <br/>
Center <br/>
$ ("#id"). Floatdiv ("Middle");</p>
<p>
3 Custom position Floating <br/>
$ ("#id"). Floatdiv ({left: ' 10px ', Top: "10px"}); <br/>
The above parameters, set the floating layer in left 10 pixels, top 10 pixel position <br/>
*/</p>
</div>
<div>hello<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
Hello
</div>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.