我是FE,也是Fe

          前端來源于不斷的點滴積累。我一直在努力。

          統(tǒng)計

          留言簿(15)

          閱讀排行榜

          評論排行榜

          去掉頁面滾動條的兩種方法

          在做彈出層的時候,頁面內(nèi)容比較高,通常監(jiān)聽頁面的滾動位置重新計算彈出層在頁面中的位置。也許也可以用position:fixed去處理,IE6又不支持position:fixed,用javascript去算位置會出現(xiàn)操作不順暢的情況,感覺“一閃一閃”的。其實換種思路去做也許也不錯,何不直接干掉頁面的滾動條呢?qq控件的照片瀏覽,以及google+中的照片瀏覽給了一些思路。

          第一種,直接設(shè)置html標(biāo)簽的溢出屬性。
          <!DOCTYPE html> 
          <html> 
          <head> 
              
          <meta charset="utf-8"> 
              
          <title>沒有滾動條的overlay</title> 
              
          <script type="text/javascript">
                  
          function go(){
                      document.documentElement.style.overflow
          ="hidden";
                      document.documentElement.style.paddingRight
          ="17px";
                      document.documentElement.style.width
          ="100%";
                  }
                  
          function reset(){
                      document.documentElement.style.overflow
          ="auto";
                      document.documentElement.style.paddingRight
          ="0px";
                      document.documentElement.style.width
          ="auto";
                  }
              
          </script>
          </head>
          <body>
          <div id="d" class="" style="height:1000px;background-color:gray;border:1px solid red; ">
              模擬頁面內(nèi)容
              
          <div id="" class="" style="height:500px;">
                  
              
          </div>
              
          <input type="button" id="" name="" onclick="go()" value="去掉頁面滾動條" />
              
          <input type="button" id="" name="" onclick="reset()" value="恢復(fù)頁面滾動條" />
          </div>
          </body>
          </html>

          利用documentElement元素(就是根htmlDOM)的"擠"走滾動條。

          第二種:利用修正position:fixed方法中的div屬性
          <!DOCTYPE html>
          <html> 
          <head> 
              
          <meta charset="utf-8"> 
              
          <title>修復(fù)IE 6不支持position:fixed & 去掉頁面滾動條</title> 
          </head>
          <body>
          <style type="text/css">
                  html,body,#content
          {height:100%;overflow:auto;padding:0px;margin:0px;}
                  #fixed
          {position:fixed; right:20px; bottom:20px; border:solid 1px  blue;_position:absolute;}
              
          </style>
          <div id="content" class="">
              
          <div id="" class="" style="background-color:#ccc;height:1000px;">
                  模擬頁面內(nèi)容
                  
          <div id="" class="" style="height:500px">
                      
                  
          </div>
                  
          <input type="button" id="" name="" value="去掉滾動條" onclick="document.getElementById('content').style.overflow='hidden';"/>
                  
          <input type="button" id="" name="" value="恢復(fù)滾動條" onclick="document.getElementById('content').style.overflow='auto';"/>
              
          </div>
          </div>
          <div id="fixed" class="">
              fixed content
          </div>
          </body>

          </html>
          因為這種修復(fù)方法中頁面的滾動條其實是div#content的滾動條,所以只要把他的滾動條去掉了。頁面也就沒有滾動條了。

          上述兩種方法思路都不錯,這樣可以放心的彈出層,只要計算一次位置就好,幾乎不影響用戶使用。




          posted on 2011-07-13 10:31 衡鋒 閱讀(3466) 評論(1)  編輯  收藏 所屬分類: Web開發(fā)

          評論

          # re: 去掉頁面滾動條的兩種方法 2011-07-13 17:41 censhao

          看見宿舍好多好多書,都當(dāng)廢紙賣了,
          太可惜,所以我拿來淘寶出售,
          賣給有需要的人.

          有興趣的話 http://pcenshao.taobao.com/

          軟件工程
          UML和模式應(yīng)用
          Unix Linux系統(tǒng)管理
          java面向?qū)ο缶幊?br>asp.net 2.0 經(jīng)典教程  回復(fù)  更多評論   

          主站蜘蛛池模板: 江西省| 万盛区| 房产| 三明市| 乌兰察布市| 响水县| 彩票| 沙洋县| 普兰店市| 延津县| 理塘县| 静海县| 清涧县| 墨脱县| 乌兰县| 沙湾县| 古蔺县| 麻江县| 景洪市| 来凤县| 伊宁市| 贵定县| 德化县| 隆子县| 永福县| 右玉县| 南皮县| 芒康县| 蛟河市| 嵩明县| 五常市| 青川县| 馆陶县| 沾化县| 彰化县| 夹江县| 习水县| 彭阳县| 富锦市| 无锡市| 安义县|