使用 CSS 的类似 Apple 的滚动条

发布于 2024-10-11 06:53:05 字数 343 浏览 0 评论 0原文

我注意到一些苹果网站,例如: http://help.apple.com/mobileme/ index.html#mm5b08c671 他们有使用最近出现的 WebKit 滚动条 CSS 内容的自定义滚动条。然而我根本无法复制它。有什么想法如何去做吗?我这里有一个测试站点,但我得到了默认的滚动条?感谢

测试:http://driz.co.uk/scrollbar/

I have noticed on some Apple sites like: http://help.apple.com/mobileme/index.html#mm5b08c671 they have custom scrollbars using the WebKit scrollbar CSS stuff that recently came out. However I am unable to replicate it at all. Any ideas how to do it? I have a test site here but I get the default scrollbars? Thanks

Test: http://driz.co.uk/scrollbar/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅黛梨妆こ 2024-10-18 06:53:05

Apple 使用的是以下 CSS 怪物:

::-webkit-scrollbar {
  width: 15px;
  height: 15px;
}
::-webkit-scrollbar-corner {
  background-image: url(https://i.sstatic.net/FguQn.png?corner.png);
  background-repeat: no-repeat;
}
::-webkit-resizer {
  background-image: url(https://i.sstatic.net/aKKDY.png?resizer.png);
  background-repeat: no-repeat;
  background-position: bottom right;
}
::-webkit-scrollbar-button:start {
  display: none;
}
::-webkit-scrollbar-button:end {
  display: block;
}
::-webkit-scrollbar:horizontal {
  -webkit-border-image: url(https://i.sstatic.net/NQ2K6.png?horizontal-button.png)
    0 2 0 2;
  border-color: transparent;
  border-width: 0 2px;
  background-image: url(https://i.sstatic.net/8xDbU.png?horizontal-button-background.png);
  background-repeat: repeat-x;
}
::-webkit-scrollbar:horizontal:corner-present {
  border-right-width: 0;
}
::-webkit-scrollbar-thumb:horizontal {
  -webkit-border-image: url(https://i.sstatic.net/YQRD7.png?horizontal-thumb.png)
    0 15 0 15;
  border-color: transparent;
  border-width: 0 15px;
  min-width: 20px;
}
::-webkit-scrollbar-track-piece:horizontal:start {
  margin-left: 6px;
}
::-webkit-scrollbar-track-piece:horizontal:end {
  margin-right: -6px;
}
::-webkit-scrollbar-track-piece:horizontal:decrement {
  -webkit-border-image: url(https://i.sstatic.net/p9yMk.png?horizontal-track.png)
    0 15 0 15;
  border-color: transparent;
  border-width: 0 0 0 15px;
}
::-webkit-scrollbar-track-piece:horizontal:increment {
  -webkit-border-image: url(https://i.sstatic.net/p9yMk.png?horizontal-track.png)
    0 15 0 15;
  border-color: transparent;
  border-width: 0 15px 0 0;
}
::-webkit-scrollbar-button:horizontal {
  width: 21px;
  -webkit-border-image: url(https://i.sstatic.net/NQ2K6.png?horizontal-button.png)
    0 2 0 2;
  border-color: transparent;
  border-width: 0 2px;
}
::-webkit-scrollbar-button:horizontal:decrement {
  background-image: url(https://i.sstatic.net/dGOKL.png?horizontal-decrement-arrow.png),
    url(https://i.sstatic.net/8xDbU.png?horizontal-button-background.png);
  background-repeat: no-repeat, repeat-x;
  background-position: 7px 4px, 0 0;
}
::-webkit-scrollbar-button:horizontal:decrement:active {
  -webkit-border-image: url(https://i.sstatic.net/gT5BM.png?horizontal-button-active.png)
    0 2 0 2;
  background-image: url(https://i.sstatic.net/dGOKL.png?horizontal-decrement-arrow.png),
    url(https://i.sstatic.net/RDf8L.png?horizontal-button-background-active.png);
}
::-webkit-scrollbar-button:horizontal:increment {
  background-image: url(https://i.sstatic.net/5rJr5.png?horizontal-increment-arrow.png),
    url(https://i.sstatic.net/8xDbU.png?horizontal-button-background.png);
  background-repeat: no-repeat, repeat-x;
  width: 16px;
  border-left-width: 0;
  background-position: 3px 4px, 0 0;
}
::-webkit-scrollbar-button:horizontal:increment:active {
  -webkit-border-image: url(https://i.sstatic.net/gT5BM.png?horizontal-button-active.png)
    0 2 0 2;
  background-image: url(https://i.sstatic.net/5rJr5.png?horizontal-increment-arrow.png),
    url(https://i.sstatic.net/RDf8L.png?horizontal-button-background-active.png);
}
::-webkit-scrollbar-button:horizontal:end:increment:corner-present {
  border-right-width: 0;
  width: 15px;
}
::-webkit-scrollbar:vertical {
  -webkit-border-image: url(https://i.sstatic.net/NdaTT.png?vertical-button.png)
    2 0 2 0;
  border-color: transparent;
  border-width: 2px 0;
  background-image: url(https://i.sstatic.net/p7j9a.png?vertical-button-background.png);
  background-repeat: repeat-y;
}
::-webkit-scrollbar:vertical:corner-present {
  border-bottom-width: 0;
}
::-webkit-scrollbar-thumb:vertical {
  -webkit-border-image: url(https://i.sstatic.net/rPEsZ.png?vertical-thumb.png)
    15 0 15 0;
  border-color: transparent;
  border-width: 15px 0;
  min-height: 20px;
}
::-webkit-scrollbar-track-piece:vertical:start {
  margin-top: 6px;
}
::-webkit-scrollbar-track-piece:vertical:end {
  margin-bottom: -6px;
}
::-webkit-scrollbar-track-piece:vertical:decrement {
  -webkit-border-image: url(https://i.sstatic.net/Rb6ru.png?vertical-track.png)
    15 0 15 0;
  border-color: transparent;
  border-width: 15px 0 0 0;
}
::-webkit-scrollbar-track-piece:vertical:increment {
  -webkit-border-image: url(https://i.sstatic.net/Rb6ru.png?vertical-track.png)
    15 0 15 0;
  border-color: transparent;
  border-width: 0 0 15px 0;
}
::-webkit-scrollbar-button:vertical {
  height: 21px;
  -webkit-border-image: url(https://i.sstatic.net/NdaTT.png?vertical-button.png)
    2 0 2 0;
  border-color: transparent;
  border-width: 2px 0;
}
::-webkit-scrollbar-button:vertical:decrement {
  background-image: url(https://i.sstatic.net/KQvwk.png?vertical-decrement-arrow.png),
    url(https://i.sstatic.net/p7j9a.png?vertical-button-background.png);
  background-repeat: no-repeat, repeat-y;
  background-position: 4px 7px, 0 0;
}
::-webkit-scrollbar-button:vertical:decrement:active {
  -webkit-border-image: url(https://i.sstatic.net/uW3TL.png?vertical-button-active.png)
    2 0 2 0;
  background-image: url(https://i.sstatic.net/KQvwk.png?vertical-decrement-arrow.png),
    url(https://i.sstatic.net/puDsH.png?vertical-button-background-active.png);
}
::-webkit-scrollbar-button:vertical:increment {
  background-image: url(https://i.sstatic.net/UjkVR.png?vertical-increment-arrow.png),
    url(https://i.sstatic.net/p7j9a.png?vertical-button-background.png);
  background-repeat: no-repeat, repeat-y;
  height: 16px;
  border-top-width: 0;
  background-position: 4px 5px, 0 0;
}
::-webkit-scrollbar-button:vertical:increment:active {
  -webkit-border-image: url(https://i.sstatic.net/uW3TL.png?vertical-button-active.png)
    2 0 2 0;
  background-image: url(https://i.sstatic.net/UjkVR.png?vertical-increment-arrow.png),
    url(https://i.sstatic.net/puDsH.png?vertical-button-background-active.png);
}
::-webkit-scrollbar-button:vertical:end:increment:corner-present {
  border-bottom-width: 0;
  height: 15px;
}
::-webkit-scrollbar:disabled {
  background: red;
  -webkit-border-image: none;
  display: none;
}
<div style="width:1000px; height:1000px">
    Hi scrollbar!
</div>

一些有用的博客文章:

The following CSS monster is what Apple is using:

::-webkit-scrollbar {
  width: 15px;
  height: 15px;
}
::-webkit-scrollbar-corner {
  background-image: url(https://i.sstatic.net/FguQn.png?corner.png);
  background-repeat: no-repeat;
}
::-webkit-resizer {
  background-image: url(https://i.sstatic.net/aKKDY.png?resizer.png);
  background-repeat: no-repeat;
  background-position: bottom right;
}
::-webkit-scrollbar-button:start {
  display: none;
}
::-webkit-scrollbar-button:end {
  display: block;
}
::-webkit-scrollbar:horizontal {
  -webkit-border-image: url(https://i.sstatic.net/NQ2K6.png?horizontal-button.png)
    0 2 0 2;
  border-color: transparent;
  border-width: 0 2px;
  background-image: url(https://i.sstatic.net/8xDbU.png?horizontal-button-background.png);
  background-repeat: repeat-x;
}
::-webkit-scrollbar:horizontal:corner-present {
  border-right-width: 0;
}
::-webkit-scrollbar-thumb:horizontal {
  -webkit-border-image: url(https://i.sstatic.net/YQRD7.png?horizontal-thumb.png)
    0 15 0 15;
  border-color: transparent;
  border-width: 0 15px;
  min-width: 20px;
}
::-webkit-scrollbar-track-piece:horizontal:start {
  margin-left: 6px;
}
::-webkit-scrollbar-track-piece:horizontal:end {
  margin-right: -6px;
}
::-webkit-scrollbar-track-piece:horizontal:decrement {
  -webkit-border-image: url(https://i.sstatic.net/p9yMk.png?horizontal-track.png)
    0 15 0 15;
  border-color: transparent;
  border-width: 0 0 0 15px;
}
::-webkit-scrollbar-track-piece:horizontal:increment {
  -webkit-border-image: url(https://i.sstatic.net/p9yMk.png?horizontal-track.png)
    0 15 0 15;
  border-color: transparent;
  border-width: 0 15px 0 0;
}
::-webkit-scrollbar-button:horizontal {
  width: 21px;
  -webkit-border-image: url(https://i.sstatic.net/NQ2K6.png?horizontal-button.png)
    0 2 0 2;
  border-color: transparent;
  border-width: 0 2px;
}
::-webkit-scrollbar-button:horizontal:decrement {
  background-image: url(https://i.sstatic.net/dGOKL.png?horizontal-decrement-arrow.png),
    url(https://i.sstatic.net/8xDbU.png?horizontal-button-background.png);
  background-repeat: no-repeat, repeat-x;
  background-position: 7px 4px, 0 0;
}
::-webkit-scrollbar-button:horizontal:decrement:active {
  -webkit-border-image: url(https://i.sstatic.net/gT5BM.png?horizontal-button-active.png)
    0 2 0 2;
  background-image: url(https://i.sstatic.net/dGOKL.png?horizontal-decrement-arrow.png),
    url(https://i.sstatic.net/RDf8L.png?horizontal-button-background-active.png);
}
::-webkit-scrollbar-button:horizontal:increment {
  background-image: url(https://i.sstatic.net/5rJr5.png?horizontal-increment-arrow.png),
    url(https://i.sstatic.net/8xDbU.png?horizontal-button-background.png);
  background-repeat: no-repeat, repeat-x;
  width: 16px;
  border-left-width: 0;
  background-position: 3px 4px, 0 0;
}
::-webkit-scrollbar-button:horizontal:increment:active {
  -webkit-border-image: url(https://i.sstatic.net/gT5BM.png?horizontal-button-active.png)
    0 2 0 2;
  background-image: url(https://i.sstatic.net/5rJr5.png?horizontal-increment-arrow.png),
    url(https://i.sstatic.net/RDf8L.png?horizontal-button-background-active.png);
}
::-webkit-scrollbar-button:horizontal:end:increment:corner-present {
  border-right-width: 0;
  width: 15px;
}
::-webkit-scrollbar:vertical {
  -webkit-border-image: url(https://i.sstatic.net/NdaTT.png?vertical-button.png)
    2 0 2 0;
  border-color: transparent;
  border-width: 2px 0;
  background-image: url(https://i.sstatic.net/p7j9a.png?vertical-button-background.png);
  background-repeat: repeat-y;
}
::-webkit-scrollbar:vertical:corner-present {
  border-bottom-width: 0;
}
::-webkit-scrollbar-thumb:vertical {
  -webkit-border-image: url(https://i.sstatic.net/rPEsZ.png?vertical-thumb.png)
    15 0 15 0;
  border-color: transparent;
  border-width: 15px 0;
  min-height: 20px;
}
::-webkit-scrollbar-track-piece:vertical:start {
  margin-top: 6px;
}
::-webkit-scrollbar-track-piece:vertical:end {
  margin-bottom: -6px;
}
::-webkit-scrollbar-track-piece:vertical:decrement {
  -webkit-border-image: url(https://i.sstatic.net/Rb6ru.png?vertical-track.png)
    15 0 15 0;
  border-color: transparent;
  border-width: 15px 0 0 0;
}
::-webkit-scrollbar-track-piece:vertical:increment {
  -webkit-border-image: url(https://i.sstatic.net/Rb6ru.png?vertical-track.png)
    15 0 15 0;
  border-color: transparent;
  border-width: 0 0 15px 0;
}
::-webkit-scrollbar-button:vertical {
  height: 21px;
  -webkit-border-image: url(https://i.sstatic.net/NdaTT.png?vertical-button.png)
    2 0 2 0;
  border-color: transparent;
  border-width: 2px 0;
}
::-webkit-scrollbar-button:vertical:decrement {
  background-image: url(https://i.sstatic.net/KQvwk.png?vertical-decrement-arrow.png),
    url(https://i.sstatic.net/p7j9a.png?vertical-button-background.png);
  background-repeat: no-repeat, repeat-y;
  background-position: 4px 7px, 0 0;
}
::-webkit-scrollbar-button:vertical:decrement:active {
  -webkit-border-image: url(https://i.sstatic.net/uW3TL.png?vertical-button-active.png)
    2 0 2 0;
  background-image: url(https://i.sstatic.net/KQvwk.png?vertical-decrement-arrow.png),
    url(https://i.sstatic.net/puDsH.png?vertical-button-background-active.png);
}
::-webkit-scrollbar-button:vertical:increment {
  background-image: url(https://i.sstatic.net/UjkVR.png?vertical-increment-arrow.png),
    url(https://i.sstatic.net/p7j9a.png?vertical-button-background.png);
  background-repeat: no-repeat, repeat-y;
  height: 16px;
  border-top-width: 0;
  background-position: 4px 5px, 0 0;
}
::-webkit-scrollbar-button:vertical:increment:active {
  -webkit-border-image: url(https://i.sstatic.net/uW3TL.png?vertical-button-active.png)
    2 0 2 0;
  background-image: url(https://i.sstatic.net/UjkVR.png?vertical-increment-arrow.png),
    url(https://i.sstatic.net/puDsH.png?vertical-button-background-active.png);
}
::-webkit-scrollbar-button:vertical:end:increment:corner-present {
  border-bottom-width: 0;
  height: 15px;
}
::-webkit-scrollbar:disabled {
  background: red;
  -webkit-border-image: none;
  display: none;
}
<div style="width:1000px; height:1000px">
    Hi scrollbar!
</div>

Some useful blog posts:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文