国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jQuery 位置插件

2019-11-21 01:30:37
字體:
供稿:網(wǎng)友
插件代碼:
/*任意位置浮動固定層*/
/*沒劍(http://regedit.cnblogs.com) 08-03-11*/
/*說明:可以讓指定的層浮動到網(wǎng)頁上的任何位置,當滾動條滾動時它會保持在當前位置不變,不會產(chǎn)生閃動*/
/*2008-4-1修改:當自定義right位置時無效,這里加上一個判斷
有值時就不設置,無值時要加18px已修正層位置在ie6下的問題
*/
/*調(diào)用:
1 無參數(shù)調(diào)用:默認浮動在右下角
$("#id").floatdiv();
2 內(nèi)置固定位置浮動
//右下角
$("#id").floatdiv("rightbottom");
//左下角
$("#id").floatdiv("leftbottom");
//右下角
$("#id").floatdiv("rightbottom");
//左上角
$("#id").floatdiv("lefttop");
//右上角
$("#id").floatdiv("righttop");
//居中
$("#id").floatdiv("middle");
3 自定義位置浮動
$("#id").floatdiv({left:"10px",top:"10px"});
以上參數(shù),設置浮動層在left 10個像素,top 10個像素的位置
*/
jQuery.fn.floatdiv=function(location){
//ie6要隱藏縱向滾動條
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;//層的絕對定位位置
if(location==undefined || location.constructor == String){
switch(location){
case("rightbottom")://右下角
loc={right:"0px",bottom:"0px"};
break;
case("leftbottom")://左下角
loc={left:"0px",bottom:"0px"};
break;
case("lefttop")://左上角
loc={left:"0px",top:"0px"};
break;
case("righttop")://右上角
loc={right:"0px",top:"0px"};
break;
case("middle")://居中
var l=0;//居左
var t=0;//居上
var windowWidth,windowHeight;//窗口的高和寬
//取得窗口的高和寬
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://默認為右下角
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修改:當自定義right位置時無效,這里加上一個判斷
//有值時就不設置,無值時要加18px已修正層位置
if($(this).css("right")==null || $(this).css("right")==""){
$(this).css("right","18px");
}
}
$(this).css("position","absolute");
}
});
};
使用方法:
<!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>
<title>任意位置浮動窗口插件</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>
</head>
<body>
<div id="rtop" style="background-color: #666633; width: 300px; height: 100px;padding:2px;color:white;">右上角</div>
<div id="floatAd" style="background-color: #667733; width: 300px; height: 100px;padding:2px;color:white;">左下角</div>
<div id="test" style="background-color: #665533; width: 300px; height: 100px;padding:2px;color:white;">
<p>
/*任意位置浮動固定層*/<br />
/*說明:可以讓指定的層浮動到網(wǎng)頁上的任何位置,當滾動條滾動時它會保持在當前位置不變,不會產(chǎn)生閃動*/<br />
/*調(diào)用:<br />
1 無參數(shù)調(diào)用:默認浮動在右下角<br />
$("#id").floatdiv();</p>
<p>
2 內(nèi)置固定位置浮動<br />
//右下角<br />
$("#id").floatdiv("rightbottom");<br />
//左下角<br />
$("#id").floatdiv("leftbottom");<br />
//右下角<br />
$("#id").floatdiv("rightbottom");<br />
//左上角<br />
$("#id").floatdiv("lefttop");<br />
//右上角<br />
$("#id").floatdiv("righttop");<br />
//居中<br />
$("#id").floatdiv("middle");</p>
<p>
3 自定義位置浮動<br />
$("#id").floatdiv({left:"10px",top:"10px"});<br />
以上參數(shù),設置浮動層在left 10個像素,top 10個像素的位置<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>
</html>
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 凯里市| 岳阳县| 沙洋县| 济阳县| 吴川市| 临城县| 乳山市| 博兴县| 锦屏县| 油尖旺区| 麻阳| 镇坪县| 兰考县| 辉县市| 芜湖县| 西丰县| 福鼎市| 东宁县| 环江| 麦盖提县| 玉树县| 康乐县| 嘉禾县| 兴隆县| 惠东县| 江阴市| 巴中市| 台州市| 湄潭县| 同心县| 华池县| 大同县| 杭州市| 扎鲁特旗| 晋江市| 永城市| 吕梁市| 民县| 济源市| 确山县| 焦作市|