简体   繁体   English

如何在Bootstrap中实现这种滚动效果?

[英]How to achieve this scrolling effect in Bootstrap?

How do I achieve this scrolling effect in Boostrap? 如何在Boostrap中实现这种滚动效果? Have a fixed image background with the content div overlayed on top when scrolling: 滚动时具有固定的图像背景,内容div覆盖在顶部:

http://www.standardhotels.com/culture/things-to-do-july-2017-new-york-los-angeles-miami http://www.standardhotels.com/culture/things-to-do-july-2017-new-york-los-angeles-miami

There are several ways you could achieve this. 有几种方法可以实现此目的。 You could fix a background image to html and offset the body, adding padding to keep text in the viewport. 您可以将背景图像固定为html并偏移正文,添加填充以将文本保留在视口中。 For example: 例如:

html {
  background: url(DESIRED BACKGROUND IMAGE) no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

body {
  background:lightblue;
  padding-left:150px;
  padding-right: 30px;
  position:relative;
  left:-150px;
  top:80%;
}

Check out this basic (but very cute) kitten example . 看看这个基本(但非常可爱)的小猫例子

EDIT 编辑

Looking further into your example's code, you could also add margin-top to the body and remove the positioning top . 进一步查看示例代码,您还可以在正文中添加margin-top并删除定位top Your example shows margin-top: calc(100vh - 140px) !important; 您的示例显示了margin-top: calc(100vh - 140px) !important;

Here's an updated version of my fiddle with the properties swapped. 这是我的小提琴的更新版本,其中交换了属性。 You can see that the effect is very similar. 您可以看到效果非常相似。

You are looking for Parallax scrolling. 您正在寻找视差滚动。 Here is the link with working demo on how to achieve this. 是有关如何实现此目标的演示工作的链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM