无论如何,首先要修复背景图像,然后滚动?

时间:2017-09-19 18:03:26

标签: html css

所以我基本上试图在我的网页上获得具有多个背景图像的滚动视差效果。我将发布一个链接到一个网站,其中包含我正在谈论的完美示例(请查看网页上的前两个背景图片)。这是该链接:https://www.wix.com/website-template/view/html/1885?originUrl=http%3A%2F%2Fwww.wix.com%2Fwebsite%2Ftemplates%2Fhtml%2Fportfolio-cv%2F1&bookName=&galleryDocIndex=0&category=portfolio-cv 然而,我的网页问题是,一旦你向下滚动到某个点,第一个背景图像就会被截断(应该如此),但是第二个背景图像会很快滚动并留下这个“空白”,在那里显示背景。我将给出一个jsfiddle链接,这样你就可以看到我在说什么。您可能必须在jsfiddle上展开视口以查看第一个背景图像。提前谢谢。

CSS:

...

HTML:

    body {
  padding: 0;
  margin: 0;
  background-color: rgb(114, 129, 139);
  overflow-x: hidden;
  animation: fadein 1s;
}
a {
  text-decoration: none;
  font-family: Tahoma, Geneva, sans-serif;
}
h1 {
  line-height: 300px;
  font-size: 90px;
  font-family: "Avant Garde", Avantgarde, "Century Gothic", CenturyGothic,
  "AppleGothic", sans-serif;
}
h2 {
  position: relative;
  bottom: 50px;
  font-size: 60px;
  font-family: "Avant Garde", Avantgarde, "Century Gothic", CenturyGothic,
  "AppleGothic", sans-serif;
}
#p_in_first_div {
  font-size: 20px;
  line-height: 120px;
  vertical-align: middle;
  font-family: "Avant Garde", Avantgarde, "Century Gothic", CenturyGothic,
  "AppleGothic", sans-serif;
}
#first_bg_image {
  display: inline-block;
  position: relative;
  width: 100%;
}
#first_bg_image::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  bottom: 0; left: 0;
  background: url(http://pngimg.com/uploads/businessman/businessman_PNG6580.png);
  background-position: 49em 0px;
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
  margin-top: -1700px;
  width: 120%;
  height: 3100px;
  opacity: 0.8;
  pointer-events: none;
  transform: scale(.80);
}
#second_bg_image {
  display: inline-block;
  position: relative;
  width: 100%;
}
#second_bg_image::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  bottom: 0; left: 0;
  background: url(https://image.freepik.com/free-photo/desktop-with-notebook-smartphone-coffee-and-laptop_1112-253.jpg);
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
  margin-top: 377px;
  height: 1600px;
  background-position: center;
  z-index: -1;
  opacity: 0.7;
  transform: scale(1, 0.8);
}
#header_div {
  width: 100%;
  height: 70px;
  box-shadow: 0px 1px 40px;
  background-color: rgb(143, 0, 46);
}
#header_nav {
  line-height: 70px;
  word-spacing: 25px;
  font-size: 13.4px;
}
#header_div_icon {
  position: relative;
  right: 50px;
  vertical-align: middle;
  width: 40px;
  height: 40px;
}
#current_link_home {
  color: rgb(190, 226, 231);
}
#first_body_div {
  height: 690px;
  width: 820px;
  background-color: rgb(69, 72, 87);
  margin-left: auto;
  margin-right: auto;
  margin-top: 15%;
  margin-bottom: 7%;
  box-shadow: 0 4px 30px 0 rgba(0, 0, 0, 0.5);
  position: relative;
}
#icon_in_div {
  margin-left: auto;
  margin-right: auto;
  display: block;
  width: 100px;
  height: 100px;
  padding: 160px 0px 0px 0px;
}
#resume_button {
  background-color: Transparent;
  border: 2px solid rgb(79, 87, 170);
  outline: none;
  font-family: "Avant Garde", Avantgarde, "Century Gothic", CenturyGothic,
  "AppleGothic", sans-serif;
  font-size: 18px;
  display: block;
  margin-left: auto;
  margin-right: auto;
  line-height: 45px;
  width: 220px;
  height: 45px;
  transition-duration: 0.4s;
}
#professional_skills_div_1 {
  width: 230px;
  height: 15px;;
  background-color: rgb(79, 87, 170);
}
#professional_skills_div_2 {
  width: 230px;
  height: 15px;
  background-color: rgb(79, 87, 170);
}
#professional_skills_div_3 {
  width: 230px;
  height: 15px;
  background-color: rgb(79, 87, 170);
}
#professional_skills_div_4 {
  width: 430px;
  height: 15px;
  background-color: rgb(79, 87, 170);
}
#professional_skills_div_5 {
  width: 280px;
  height: 15px;
  background-color: rgb(79, 87, 170);
}
#professional_skills_div_6 {
  width: 480px;
  height: 15px;
  background-color: rgb(79, 87, 170);
}
#professional_skills_div_7 {
  width: 480px;
  height: 15px;
  background-color: rgb(79, 87, 170);
}
#professional_skill_percentage_80 {
  font-size: 15px;
  font-family: Tahoma, Geneva, sans-serif;
  text-align: left;
  position: relative;
  right: -20px;
  top: -4px;
}
#professional_skill_percentage_60 {
  font-size: 15px;
  font-family: Tahoma, Geneva, sans-serif;
  text-align: left;
  position: relative;
  right: 130px;
  top: -3px;
}
.h2_line_heights {
  line-height: 450px;
}
.other_links {
  color: rgb(114, 129, 139);
}
.text_align {
  text-align: center;
}
.text_color {
  color: rgb(190, 226, 231);
}
.h2_subheadings_font {
  font-size: 30px;
}
.h2_subheadings_positions {
  position: relative;
  top: -260px;
}
.professional_divs {
  position: relative;
  right: 32px;
  height: 45px;
  top: -210px;
  width: 1400px;
  margin-left: auto;
  margin-right: auto;
}
.professional_outside_divs {
  display: inline-block;
  width: 35%;
}
.professional_paragraphs {
  font-size: 15px;
  font-family: Tahoma, Geneva, sans-serif;
  text-align: right;
  position: relative;
  right: 40px;
  top: -4px;
}
.professional_outside_skill_bar_divs {
  width: 29%;
  display: inline-block;
  position: relative;
  right: 1.5vw;
}
.professional_skill_percentages_50 {
  font-size: 15px;
  font-family: Tahoma, Geneva, sans-serif;
  position: relative;
  right: 180px;
  top: -4px;
}
.professional_skill_percentage_90 {
  font-size: 15px;
  font-family: Tahoma, Geneva, sans-serif;
  position: relative;
  left: 70px;
  top: -3px;
}

JSFIDDLE链接:https://jsfiddle.net/245uqz0p/

1 个答案:

答案 0 :(得分:0)

我认为此链接可能会对您有所帮助。

w3school parallax effect