javascript - 位置 :fixed; 的平滑滚动问题

标签 javascript jquery css scroll

我正在尝试使用这样的平滑滚动效果:Smooth scroll effect

我发现 position:fixed;(或绝对)是问题的根源。如果我更改此值,它会完美地工作,但我不能,因为我有一个覆盖视口(viewport)的 bg 图像并且无法找到解决它的方法。

我该如何解决这个问题?我找到了这个 article我认为这可以解决问题,但我似乎无法实现。

我用来定位背景图片的 css 如下所示:

.bg {
  background-repeat:no-repeat;
  background-position:center center; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  width:100%;
  height:100%;
  position:fixed;
  background-image: url( http://lorempixel.com/400/200/);
}

Jsfiddle

最佳答案

就我个人而言,我会修复左上角的 div,而不是将整个页面内容包裹在其中。

jsfiddle:https://jsfiddle.net/jhyvcgv7/1/

.bg {
  background-repeat:no-repeat;
  background-position:center center; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  width:100%;
  height:100%;
  position:fixed;
  background-image: url( http://lorempixel.com/400/200/);
  top: 0; 
  left: 0;
  z-index: -1;
}

关于javascript - 位置 :fixed; 的平滑滚动问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44767658/

相关文章:

javascript - Discord Bot 无法按名称或 ID 找到 channel

javascript - 将多个变量从express传递到jade

javascript - Clean-Css 任务在 gulpfile : cannot read property 'on' 中给出错误

jquery - 如何无限循环播放该动画?

html - Angular 并排显示 2 张卡片

jquery - 使用 bootstrap 将文本重叠在图像上

javascript - jquery - 如何在悬停时更改 li 中按钮的显示 css 属性

javascript - 添加/插入到 Ext.ToolBar 的工具栏项目未显示在页面上

javascript - 使用 JQuery 将行追加到表中

javascript - 动态添加内容后如何计算div的高度?