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

首頁(yè) > 語(yǔ)言 > JavaScript > 正文

jquery任意位置浮動(dòng)固定層插件用法實(shí)例

2024-05-06 16:21:01
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

這篇文章主要介紹了jquery任意位置浮動(dòng)固定層插件用法,實(shí)例分析了jQuery浮動(dòng)層插件的相關(guān)使用技巧,需要的朋友可以參考下

本文實(shí)例講述了jquery任意位置浮動(dòng)固定層插件用法。分享給大家供大家參考。具體分析如下:

說(shuō)明:可以讓指定的層浮動(dòng)到網(wǎng)頁(yè)上的任何位置,當(dāng)滾動(dòng)條滾動(dòng)時(shí)它會(huì)保持在當(dāng)前位置不變,不會(huì)產(chǎn)生閃動(dòng)

2009-06-10修改:重新修改插件實(shí)現(xiàn)固定浮動(dòng)層的方式,使用一個(gè)大固定層來(lái)定位

2009-07-16修改:修正IE6下無(wú)法固定在top上的問(wèn)題

09-11-5修改:當(dāng)自定義層的絕對(duì)位置時(shí),加上top為空值時(shí)的判斷

這次的方法偷自天涯新版頁(yè)

經(jīng)多次測(cè)試,基本上沒(méi)bug~

調(diào)用:

1 無(wú)參數(shù)調(diào)用:默認(rèn)浮動(dòng)在右下角

$("#id").floatdiv();

2 內(nèi)置固定位置浮動(dòng)

 

 
  1. //右下角  
  2. $("#id").floatdiv("rightbottom");  
  3. //左下角  
  4. $("#id").floatdiv("leftbottom");  
  5. //右下角  
  6. $("#id").floatdiv("rightbottom");  
  7. //左上角  
  8. $("#id").floatdiv("lefttop");  
  9. //右上角  
  10. $("#id").floatdiv("righttop");  
  11. //居中  
  12. $("#id").floatdiv("middle");  

另外新添加了四個(gè)新的固定位置方法

middletop(居中置頂)、middlebottom(居中置低)、leftmiddle、rightmiddle

3 自定義位置浮動(dòng)

$("#id").floatdiv({left:"10px",top:"10px"});

以上參數(shù),設(shè)置浮動(dòng)層在left 10個(gè)像素,top 10個(gè)像素的位置

 

 
  1. jQuery.fn.floatdiv=function(location){  
  2. //判斷瀏覽器版本  
  3. var isIE6=false;  
  4. var Sys = {};  
  5. var ua = navigator.userAgent.toLowerCase();  
  6. var s;  
  7. (s = ua.match(/msie ([/d.]+)/)) ? Sys.ie = s[1] : 0;  
  8. if(Sys.ie && Sys.ie=="6.0"){  
  9. isIE6=true;  
  10. }  
  11. var windowWidth,windowHeight;//窗口的高和寬  
  12. //取得窗口的高和寬  
  13. if (self.innerHeight) {  
  14. windowWidth=self.innerWidth;  
  15. windowHeight=self.innerHeight;  
  16. }else if (document.documentElement&&document.documentElement.clientHeight) { 
  17. windowWidth=document.documentElement.clientWidth;  
  18. windowHeight=document.documentElement.clientHeight;  
  19. else if (document.body) {  
  20. windowWidth=document.body.clientWidth;  
  21. windowHeight=document.body.clientHeight;  
  22. }  
  23. return this.each(function(){  
  24. var loc;//層的絕對(duì)定位位置  
  25. var wrap=$("<div></div>");  
  26. var top=-1;  
  27. if(location==undefined || location.constructor == String){  
  28. switch(location){  
  29. case("rightbottom")://右下角  
  30. loc={right:"0px",bottom:"0px"};  
  31. break;  
  32. case("leftbottom")://左下角  
  33. loc={left:"0px",bottom:"0px"};  
  34. break;  
  35. case("lefttop")://左上角  
  36. loc={left:"0px",top:"0px"};  
  37. top=0;  
  38. break;  
  39. case("righttop")://右上角  
  40. loc={right:"0px",top:"0px"};  
  41. top=0;  
  42. break;  
  43. case("middletop")://居中置頂  
  44. loc={left:windowWidth/2-$(this).width()/2+"px",top:"0px"};  
  45. top=0;  
  46. break;  
  47. case("middlebottom")://居中置低  
  48. loc={left:windowWidth/2-$(this).width()/2+"px",bottom:"0px"};  
  49. break;  
  50. case("leftmiddle")://左邊居中  
  51. loc={left:"0px",top:windowHeight/2-$(this).height()/2+"px"};  
  52. top=windowHeight/2-$(this).height()/2;  
  53. break;  
  54. case("rightmiddle")://右邊居中  
  55. loc={right:"0px",top:windowHeight/2-$(this).height()/2+"px"};  
  56. top=windowHeight/2-$(this).height()/2;  
  57. break;  
  58. case("middle")://居中  
  59. var l=0;//居左  
  60. var t=0;//居上  
  61. l=windowWidth/2-$(this).width()/2;  
  62. t=windowHeight/2-$(this).height()/2;  
  63. top=t;  
  64. loc={left:l+"px",top:t+"px"};  
  65. break;  
  66. default://默認(rèn)為右下角  
  67. location="rightbottom";  
  68. loc={right:"0px",bottom:"0px"};  
  69. break;  
  70. }  
  71. }else{  
  72. loc=location;  
  73. alert(loc.bottom);  
  74. var str=loc.top;  
  75. //09-11-5修改:加上top為空值時(shí)的判斷  
  76. if (typeof(str)!= 'undefined'){  
  77. str=str.replace("px","");  
  78. top=str;  
  79. }  
  80. }  
  81. /*fied ie6 css hack*/ 
  82. if(isIE6){  
  83. if (top>=0)  
  84. {  
  85. wrap=$("<div style=/"top:e­xpression(documentElement.scrollTop+"+top+");/"></div>");  
  86. }else{  
  87. wrap=$("<div style=/"top:e­xpression(documentElement.scrollTop+documentElement.clientHeight-this.offsetHeight);/"></div>"); 
  88. }  
  89. }  
  90. $("body").append(wrap);  
  91. wrap.css(loc).css({position:"fixed",z_index:"999"});  
  92. if (isIE6)  
  93. {  
  94. wrap.css("position","absolute");  
  95. //沒(méi)有加這個(gè)的話,ie6使用表達(dá)式時(shí)就會(huì)發(fā)現(xiàn)跳動(dòng)現(xiàn)象  
  96. //至于為什么要加這個(gè),還有為什么要加nothing.txt這個(gè),偶也不知道,希望知道的同學(xué)可以告訴我  
  97. $("body").css("background-attachment","fixed").css("background-image","url(n1othing.txt)");  
  98. }  
  99. //將要固定的層添加到固定層里  
  100. $(this).appendTo(wrap);  
  101. });  
  102. }; 

完整實(shí)例代碼點(diǎn)擊此處本站下載。

希望本文所述對(duì)大家的jQuery程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 略阳县| 安达市| 天门市| 菏泽市| 九龙城区| 遵化市| 宜黄县| 拜城县| 虎林市| 昌邑市| 英吉沙县| 东台市| 桂东县| 宁陵县| 武宣县| 白河县| 浪卡子县| 陵川县| 孝义市| 宜昌市| 额尔古纳市| 长泰县| 西乌珠穆沁旗| 含山县| 葵青区| 汤原县| 周宁县| 繁昌县| 大足县| 商南县| 叶城县| 东乡族自治县| 太湖县| 洛隆县| 施秉县| 眉山市| 都昌县| 黔江区| 桓仁| 西乡县| 建昌县|