不滾動時隱藏自訂捲軸,滾動自訂捲軸

來源:互聯網
上載者:User

不滾動時隱藏自訂捲軸,滾動自訂捲軸

現在部分瀏覽器已支援自訂捲軸,成了設計師和完美主義者的救星。新版上線後,設計師又提了個新需求: 把導覽列右側的捲軸,在不滾動時隱藏掉(同時還發了個小視頻表示效果)。就是中右側的粗線: 在mac系統下測試了Chrome/Safari/Firefox瀏覽器,發現這些系統在預設情況下,不滾動時捲軸是隱藏的。如

原來是自訂捲軸屏蔽了系統的這一特性。

 解決方案:將外包裹層預設設定為overflow-y: hidden; 同時設定hover效果時overflow: auto; 如下: 
<!DOCTYPE html><html><head>  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  <style>  .content{    width: 200px;    height: 150px;    padding-left: 10px;    border: 1px solid #ccc;    overflow-y: hidden;  }  .content:hover{    overflow-y: auto;  }  .scrollbar::-webkit-scrollbar {    width: 2px;  }  .scrollbar::-webkit-scrollbar-track-piece {    background-color: #fff;  } /* 捲軸的內層滑軌背景顏色 */  .scrollbar::-webkit-scrollbar-track {    background-color: #fff;  } /* 捲軸的外層滑軌背景顏色 */  .scrollbar::-webkit-scrollbar-thumb {    background-color: #d4d8e2;  } /* 捲軸的內層滑塊顏色 */  .scrollbar::-webkit-scrollbar-button {    background-color: #fff;    display: none;  } /* 滑軌兩頭的監聽按鈕顏色 */  </style></head><body>  <div class="content scrollbar">    <p>內容1</p>    <p>內容2</p>    <p>內容3</p>    <p>內容4</p>    <p>內容5</p>    <p>內容6</p>    <p>內容7</p>  </div></body></html>

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.