javascript - 段落在底部淡出

标签 javascript css

我正在尝试为段落添加淡出效果,这是我所做的: 1

但是当我向下滚动时,淡入淡出效果不会粘在 div 的底部: 2

我还在这个代码笔中复制了这个问题:https://codepen.io/bij0520/pen/XoQpEW有什么办法可以让淡出效果一直停留在div的底部吗?谢谢。

.container{
  position:relative;
  width:300px;
  max-height:100px;
  overflow-y:scroll;
}
.container:after{
  content:"";
  position:absolute;
  z-index:1;
	bottom:0;
	pointer-events: none;
	background-image: linear-gradient(to bottom, rgba(255,255,255,0), rgba(255,255,255, 1) 90%);
	width: 100%;
	height: 4rem;
}
<div class="container">
  <p>
   Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. 
  </p>
</div>

最佳答案

我对样式表做了一点改动。你想要 p 滚动,而不是容器。

.container{
      position:relative;
      width:300px;
      max-height:100px;  
    }
    .container p {
      overflow-y:scroll;
      max-height:100px;
    }
    .container:after{
      content:"";
      position:absolute;
      z-index:1;
    	bottom:0;
    	pointer-events: none;
    	background-image: linear-gradient(to bottom, rgba(255,255,255,0), rgba(255,255,255, 1) 90%);
    	width: 100%;
    	height: 4rem;
    }
<div class="container">
  <p>
   Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. 
  </p>
</div>

关于javascript - 段落在底部淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54220452/

相关文章:

javascript - 制作响应式网格

javascript - 如何使用 Javascript 区分 CSS 中的类

html - 打印重复背景的任何解决方法?

html - SVG图像作为背景图像时如何修改填充颜色?

javascript - node.js 模拟 sendmailer 传输器内部函数

javascript - 创建分页 div 列表的更好方法

css - Primefaces 在 IE 上看起来不一样 - CSS 问题

javascript - 将鼠标悬停在文本上以显示图像

javascript - 将对象数组的值与字符串进行比较 - 返回 bool 值

javascript - 防止按钮永久消失