Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
889 views
in Technique[技术] by (71.8m points)

javascript - Contents overlaying the image while scrolling

I request you to first have a look at https://www.womentechmakers.com/ and scroll a bit. The overlaying effect on the image as we scroll is what i want to do. Can you please suggest the css/javascript to do this! Thank you!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use the background-attachment:fixed CSS property to achieve this. A very quick demonstration can be seen below:

html,
body {
  margin: 0;
  padding: 0;
}
html {
  background: url(http://lorempixel.com/800/600);
  background-attachment: fixed; /*This stops the image scrolling*/
}
body {
  min-height: 100vh;
  margin-top: calc(100vh - 100px);/*Only 100px of screen visible*/
  background: lightgray;/*Set a background*/
}
<body>Some text that will scroll</body>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...