简体   繁体   中英

Can you use css to resize and crop background images instantaneously?

I have come across a problem while trying to make a background for my website. I am trying to have an image that can be scrolled and resized as seen on: https://sketchthemes.com/preview/?theme=98 . I have tried this:

<div id="back_img" style="background-image: url("test.jpg");"></div>

And then setting the style to:

#back_img {

  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

But this does not contain all of the functionalities I wished for.

Setting background-attachment: fixed; and background-size: cover; will bring it closer to that effect, however to get the parallax scrolling you will need to write / use a script to adjust it's position based on the current scroll.

#back_img {

  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
  background-attachment: fixed;
  background-size: cover;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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