【问题标题】:Scroll bar on the bottom of the page页面底部的滚动条
【发布时间】:2018-05-03 15:43:01
【问题描述】:

想要在此页面上获得与此水平滚动条相同的结果:https://www.claytonbozard.com/#5

我需要创建一个看起来像默认底部滚动条的滚动条,并且始终放置在页面底部,并且只会滚动特定部分。 (不是所有页面,只有一个特定部分)有人可以帮助我吗?

我写了这段代码,但滚动条没有放在页面底部:

.wrapper {
  /* background: #EFEFEF; */
  /* box-shadow: 1px 1px 10px #999; */
  margin: auto;
  text-align: center;
  position: relative;
  /* margin-bottom: 20px !important; */
  width: 100%;
  /* padding-top: 5px; */
}

.scrolls {
  overflow-x: scroll;
  overflow-y: hidden;
  /* height: 300px; */
  white-space: nowrap;
}

.scrolls img {
  width: 20%;
  cursor: pointer;
  display: inline-block;
  display: inline;
  margin-right: -5px;
  vertical-align: top;
}
<div class="wrapper">
  <div class="scrolls">
    <img src="images/01.jpg" />
    <img src="images/04.jpg" />
    <img src="images/07.jpg" />
  </div>
</div>

【问题讨论】:

  • 对于将来寻求此问题的任何人,只需在非滚动部分使用position:fixed,即可在相关页面(如果仍然存在)上实现这一点。不需要 jquery 或鼠标滚轮插件。

标签: javascript jquery css scroll


【解决方案1】:

完全正确。 对于水平滚动 - 你需要一个 jQuery 库和鼠标滚轮插件。

$(document).ready(function () {
    $('.horizontal-scroll').mousewheel(function(e, delta) {
        this.scrollLeft -= (delta * 40);
        e.preventDefault();
    });
});
.horizontal-scroll {
  
 max-width: 100%;
 overflow: scroll;
 width: 100%;
 display: block;
}
ul {
    white-space:nowrap;
}
li { display: inline-block; width: 300px; height: 300px; background: red; border: 2px solid black; margin: 5px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://css-tricks.com/examples/HorzScrolling/jquery.mousewheel.js"></script>
<div class="horizontal-scroll">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>

【讨论】:

  • 我怎样才能将页脚放在滚动条上方并使其在滚动时不移动(只有画廊会移动)像这里claytonbozard.com/#5
  • 向 .horizo​​ntal-scroll 添加一个 padding-bottom,它与页脚高度相等。并使页脚位置:固定;底部:0;
【解决方案2】:

使用this plugin 并添加此代码

$("body").mousewheel(function(evt, chg) {
  this.scrollLeft -= (chg * 50); //need a value to speed up the change
  evt.preventDefault();
});

答案here

【讨论】:

    猜你喜欢
    • 2019-02-27
    • 2014-08-26
    • 2011-05-14
    • 1970-01-01
    • 2012-07-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多