在滚动的梯度退色文本在背景顶部 [英] Gradient fading text on scroll on top of background

查看:67
本文介绍了在滚动的梯度退色文本在背景顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一直在寻找一种在顶部和底部褪色滚动的方法。
我知道你在顶部和底部使用2 png的方式,问题是,在纯色页面上滚动时,似乎只是有用。
但我希望它发生在页面上有一个背景图像..

Been looking for a way to fade a scroll in top and bottom. I know the way where you use 2 png in top and bottom, problem is that only seems to be usefull when scroll in on a solid color page. But i want it to happen on page where the there is a background image..

任何想法?如果它甚至可能?
JS,HTML5,CSS?

Any ideas? if its even possible? JS, HTML5, CSS?

以下是描述效果的图片:

Here is a picture to describe the effect:

推荐答案

这可能是你要找的。

>

JSFiddle

<div class="wrap">
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna.</p>
    <div class="fader"></div>
</div>​



CSS



CSS

.wrap {
    position: relative;
    background: url(http://lorempixel.com/output/fashion-q-c-640-480-3.jpg);
    font-family: Helvetica, 'Helvetica Neue', sans-serif;
}

.wrap p {
    color: white;
}

.fader {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(top, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0) 30%, rgba(0,0,0,0) 70%, rgba(0,0,0,0.7) 100%);
    background: -webkit-linear-gradient(top, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0) 30%, rgba(0,0,0,0) 70%, rgba(0,0,0,0.7) 100%);
    background: -moz-linear-gradient(top, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0) 30%, rgba(0,0,0,0) 70%, rgba(0,0,0,0.7) 100%);
    pointer-events: none;
}

编辑:添加 pointer-events:none 到CSS以允许正常的文本选择。

Added pointer-events: none to CSS to allow normal text selection.

这篇关于在滚动的梯度退色文本在背景顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆