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
231 views
in Technique[技术] by (71.8m points)

javascript - How to make image inside div tag always a percentage larger than the container?

I'm currently using parallax.js (https://github.com/wagerfield/parallax) to get a parallax effect on a hero image on my page. I am trying to use a div tag to use as a "frame" so the image doesn't "appear" floating. I basically want the image to be a percentage larger than the div tag so as the image moves the container is fully covered by the image. This is what's happening. And not what I want. Hope this makes sense.

TIA

Here is my code:

<div id="scene" data-relative-input="true" class="float-image" style="border: 20px solid red; overflow: hidden;">
                <img src="img/#.jpg" data-depth="0.2" class="cover-img">
                <img src="img/#.png" data-depth="0.1" class="cover-img">
</div>

CSS:

#scene {
    position: relative;
}

.cover-img {
    max-height: 100%;
    max-width: 100%;
 }

.float-image {
z-index: -1;
object-fit: cover;
flex-shrink: 0;
min-width: 100%;
min-height: 100%;
}
question from:https://stackoverflow.com/questions/65837523/how-to-make-image-inside-div-tag-always-a-percentage-larger-than-the-container

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

1 Reply

0 votes
by (71.8m points)
Waitting for answers

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

...