javascript - 如何使网页中的表格垂直滚动,同时使其他所有内容固定在适当的位置

标签 javascript jquery html css scroll

我想在我的网页中滚动一个特定的表格,用鼠标滚动事件垂直滚动,同时保持包括背景图像在内的所有其他内容固定在适当的位置。

这是我的表格的CSS脚本

@media screen and (min-width: 480px) {
            table{
              background-color: rgba(255, 255, 0, 0.7);
              text-align: center;
              font-family: opensans;
              font-size: 20px;
              color: rgba(0, 0, 0, 255);
              width: 70vw;
              height: 100px;
              overflow-y: scroll;
              overflow-x: hidden;
            }
          }

这是背景和标题的脚本

body{
            background-color: rgba(0, 0, 0, 255);
            background: url("background.jpg");
            background-position: 49% 20%;
            background-repeat: no-repeat;
            background-blend-mode: luminosity;
          }

.Header{
            font-family: Neon;
            font-size: 40px;
            position: fixed;
            letter-spacing: 1px;
            top: 0;
            left: 0;
            width: 100%;
            line-height: 35px;
            text-align: center;
            color: rgb(255, 0, 0);
          }

不幸的是,页眉仍然固定在它的位置,但页面的背景不是。我尝试添加如下固定的背景位置

body{
            background-color: rgba(0, 0, 0, 255);
            background: url("background.jpg");
            background-position: fixed;
            background-repeat: no-repeat;
            background-blend-mode: luminosity;
          }

但是滚动时背景仍然上升(垂直滚动)。

最佳答案

overflow-y: auto 将表格包裹在一个 div 中,并将 div 的高度设置为,例如 100px

关于javascript - 如何使网页中的表格垂直滚动,同时使其他所有内容固定在适当的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57239265/

相关文章:

javascript - 用于显示/隐藏元素的 JQuery 过滤器复选框

javascript - Keystone JS View 上的事件不起作用

JavaScript FancyTree : is it possible to distinguish between the selection of a node and the action of expanding it.

php - 从具有相同名称的多个选择框中获取值?在 jquery 和 php 中包含它的值

javascript - jQuery Click 事件 CheckBox 改变 Ajax 调用

javascript - iframe 加载是否会阻止 javascript 执行?

html - Bootstrap - 多语言 2 方向支持的良好做法?

javascript - 为什么事件处理程序不适用于在 javascript 中的其他函数上创建的元素

javascript - Google 图表树形图工具提示中的数字格式

javascript - 在水平列表上用鼠标滚轮水平滚动