CSS揭秘--笔记--滚动提示

我们实现的最终效果如下
这里写图片描述
目录结构如下

<ul>    
    <li>Ada Catlace</li>    
    <li>Alan Purring</li>
    <li>Schrödingcat</li>
    <li>Tim Purrners-Lee</li>
    <li>Webkitty</li>   
    <li>Json</li>
    <li>Void</li>
    <li>Neko</li>   
    <li>NaN</li>
    <li>Cat5</li>
    <li>Vector</li>
</ul>

css代码如下

ul {
    display: inline-block;
    overflow: auto;
    width: 7.2em;
    height: 7em;
    border: 1px solid silver;
    padding: .3em .5em;
    list-style: none;
    margin-top: 2em;
    font: 100 200%/1.6 'Frutiger LT Std', sans-serif;
    background: linear-gradient(white 15px, hsla(0,0%,100%,0)) 0 0 / 100% 50px,
                radial-gradient(at top, rgba(0,0,0,.2), transparent 70%) 0 0 / 100% 15px,
                linear-gradient(to top, white 15px, hsla(0,0%,100%,0)) bottom / 100% 50px,
                radial-gradient(at bottom, rgba(0,0,0,.2), transparent 70%) bottom / 100% 15px;
    background-repeat: no-repeat;
    background-attachment: local, scroll, local, scroll;
    margin-top: 30px;
}

实现这种特效的关键点在background-attachment属性,
If a background-image is specified, the background-attachment CSS property determines whether that image’s position is fixed within the viewport, or scrolls along with its containing block.
这个属性实现的是 如果存在背景图片,则该属性可以定义图片的位置,是相对于视图固定或是随着页面内容滚动。
具体属性如下(MDN描述)
Values

fixed
This keyword means that the background is fixed with regard to the viewport. Even if an element has a scrolling mechanism, a ‘fixed’ background doesn’t move with the element.
local
This keyword means that the background is fixed with regard to the element’s contents: if the element has a scrolling mechanism, the background scrolls with the element’s contents, and the background painting area and background positioning area are relative to the scrollable area of the element rather than to the border framing them.
scroll
This keyword means that the background is fixed with regard to the element itself and does not scroll with its contents. (It is effectively attached to the element’s border.)

为了实现这个效果,我们需要两成背景,一层用来生成那条阴影,一层生成用来遮挡阴影的白色矩形,起作用类似于遮挡层,生成阴影的那层具有background-attachment 默认的值scroll, 遮挡背景的background-attachment 值为local,这样就会在我们滚动到最边缘是遮挡住阴影。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值