一直在寻找一种淡化顶部和底部卷轴的方法。 我知道你在顶部和底部使用2 png的方式,问题是在纯色页面上滚动时似乎只是有用。 但我希望它发生在有背景图像的页面上..
有什么想法吗?如果它甚至可能吗? JS,HTML5,CSS?
这是描述效果的图片:
答案 0 :(得分:1)
这可能就是你要找的东西。
<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>
.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;
}
修改:为CSS添加了pointer-events: none
以允许正常的文字选择。
答案 1 :(得分:0)
这是我尝试过的,似乎有用的东西:
<html>
<head>
<title></title>
<style type="text/css">
div.bg
{
position: absolute;
top: 0px;
left: 0px;
z-index: 0;
width: 800px;
height: 600px;
background: url([your_background_image]);
}
div.txt
{
position: absolute;
top: 0px;
left: 50px;
z-index: 2;
width: 700px;
height: 600px;
font-family: Arial;
font-size: 30px;
color: #FFFFFF;
font-weight: bold;
}
div.fader_in
{
position: absolute;
top: 0px;
left: 0px;
z-index: 4;
width: 800px;
height: 100px;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#000000', endColorstr='#FFFFFF'); /* for IE */
background: -webkit-gradient(linear, left top, left bottom, from(#000000), to(#FFFFFF)); /* for webkit browsers */
background: -moz-linear-gradient(top, #000000, #FFFFFF); /* for firefox 3.6+ */
opacity: .5;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
}
div.between
{
position: absolute;
top: 100px;
left: 0px;
z-index: 4;
width: 800px;
height: 400px;
background: #FFFFFF;
opacity: .5;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
}
div.fader_out
{
position: absolute;
top: 500px;
left: 0px;
z-index: 4;
width: 800px;
height: 100px;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFFFFF', endColorstr='#000000'); /* for IE */
background: -webkit-gradient(linear, left top, left bottom, from(#FFFFFF), to(#000000)); /* for webkit browsers */
background: -moz-linear-gradient(top, #FFFFFF, #000000); /* for firefox 3.6+ */
opacity: .5;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
}
</style>
</head>
<body>
<div class="bg">
</div>
<div class="txt">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div class="fader_in"></div>
<div class="between"></div>
<div class="fader_out"></div>
</body>
</html>
答案 2 :(得分:0)
您可以使用与顶部和底部的bg颜色相匹配的透明灰度渐变图像: http://www.cssplay.co.uk/menu/fade_scroll.html
答案 3 :(得分:0)
有趣的问题......令人讨厌的是,不可能以一种不会导致可用性问题的好方式 - 即将不透明蒙版应用于实际文本层。但是你可以用一些沉重的JavaScript / Canvas来实现它,或者你可以使用这个疯狂的方法(这只有在你的背景图像的background-attachment
设置为fixed
时才有效):
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
body {
background: url(http://maxcdn.crazyleafdesign.com/blog/wp-content/uploads/2008/09/cool-wallpapers-for-designers-29.jpg) fixed;
}
#scrollable {
position: relative;
width: 400px;
height: 200px;
margin: 50px;
}
#scrollable .viewport {
position: relative;
overflow: auto;
width: 100%;
height: 100%;
}
#scrollable .text {
color: #fff;
}
#scrollable .text p {
margin: 0; padding: 0; margin-bottom: 20px;
}
#scrollable .top {
position: absolute; left: 0; top: 0; right: 0; height: 40px;
}
#scrollable .bot {
position: absolute; left: 0; bottom: 0; right: 0; height: 40px;
}
#scrollable .top div, #scrollable .bot div {
position: relative;
background: url(http://maxcdn.crazyleafdesign.com/blog/wp-content/uploads/2008/09/cool-wallpapers-for-designers-29.jpg) fixed;
height: 2px;
border: 0;
}
#scrollable .l01 { opacity: 1; }
#scrollable .l02 { opacity: 0.95; }
#scrollable .l03 { opacity: 0.9; }
#scrollable .l04 { opacity: 0.85; }
#scrollable .l05 { opacity: 0.8; }
#scrollable .l06 { opacity: 0.75; }
#scrollable .l07 { opacity: 0.7; }
#scrollable .l08 { opacity: 0.65; }
#scrollable .l09 { opacity: 0.6; }
#scrollable .l10 { opacity: 0.55; }
#scrollable .l11 { opacity: 0.5; }
#scrollable .l12 { opacity: 0.45; }
#scrollable .l13 { opacity: 0.4; }
#scrollable .l14 { opacity: 0.35; }
#scrollable .l15 { opacity: 0.3; }
#scrollable .l16 { opacity: 0.25; }
#scrollable .l17 { opacity: 0.2; }
#scrollable .l18 { opacity: 0.15; }
#scrollable .l19 { opacity: 0.1; }
#scrollable .l20 { opacity: 0.05; }
</style>
</head>
<body>
<div id="scrollable">
<div class="viewport">
<div class="text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse et blandit ligula. Vestibulum sodales porttitor sollicitudin. Etiam turpis purus, tincidunt rhoncus interdum ut, mollis vitae mi. Nulla a mauris et orci scelerisque egestas a nec metus. Cras a massa id quam vehicula sodales. Etiam aliquam justo eu ligula volutpat blandit. Sed sagittis, arcu ut pulvinar blandit, purus mauris euismod felis, eget rutrum nunc arcu vitae augue. Cras magna quam, consectetur at lobortis quis, interdum eget tortor.</p>
<p>Pellentesque tincidunt molestie urna, ut lacinia justo cursus a. Nunc mauris sem, dignissim id mollis vel, adipiscing nec purus. Fusce feugiat sem et neque cursus pretium. Curabitur tellus nunc, blandit sit amet aliquam tempus, scelerisque eu nulla. Vestibulum imperdiet nunc nec purus dignissim vitae suscipit orci pharetra. Mauris sit amet ante sit amet odio ultricies interdum auctor sit amet nibh. Integer ut sem leo, at vulputate felis. Mauris sit amet neque tortor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</p>
<p>Mauris lectus leo, luctus non malesuada vitae, facilisis vitae est. Maecenas sed neque lorem, vitae dignissim ante. Cras non lectus sed orci ornare ultricies at ac lectus. Donec quis quam mi, id ornare mauris. Praesent aliquet turpis hendrerit dui fringilla ullamcorper. Morbi facilisis urna non dui bibendum non semper neque dignissim. Vestibulum non pretium justo. Phasellus magna velit, commodo ut facilisis et, hendrerit vitae sem. Curabitur commodo eros a dolor sagittis egestas. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</div>
<div class="top">
<div class="l01"></div><div class="l02"></div><div class="l03"></div>
<div class="l04"></div><div class="l05"></div><div class="l06"></div>
<div class="l07"></div><div class="l08"></div><div class="l09"></div>
<div class="l10"></div><div class="l11"></div><div class="l12"></div>
<div class="l13"></div><div class="l14"></div><div class="l15"></div>
<div class="l16"></div><div class="l17"></div><div class="l18"></div>
<div class="l19"></div><div class="l20"></div>
</div>
<div class="bot">
<div class="l20"></div><div class="l19"></div><div class="l18"></div>
<div class="l17"></div><div class="l16"></div><div class="l15"></div>
<div class="l14"></div><div class="l13"></div><div class="l12"></div>
<div class="l11"></div><div class="l10"></div><div class="l09"></div>
<div class="l08"></div><div class="l07"></div><div class="l06"></div>
<div class="l05"></div><div class="l04"></div><div class="l03"></div>
<div class="l02"></div><div class="l01"></div>
</div>
</div>
</body>
</html>
我不建议使用迄今为止发布的任何这些方法(包括我的),因为它们都会因文本上方的浮动层而干扰文本选择和滚动条。这可能导致各种可用性问题,并且基本上只会惹恼您的用户......这不是大多数网站的目标;)