Can someone assist me with building an iPhone Mockup with scrolling Content? I want the Mockup to be positioned in the middle of a web page. Specifically, when I scroll down and the iPhone is visible, I would like it to remain sticky so that only the content within the phone itself scrolls.
If you'd like to see this behaviour in action, check out the following link: https://jsfiddle.net/rick7240/z62c7v43/
.iphone-mockup {
background-color: lightgray;
}
.iphone-mockup-container {
margin-left: auto;
margin-right: auto;
height: 100%;
width: 80%;
max-width: 400px;
background-color: purple;
position: relative;
z-index: 5;
}
.iphone-mockup-phone {
z-index: 10;
position: absolute;
width: 100%;
height: 100%;
background-image: url('https://www.donkey.de/wp-content/uploads/2020/08/iphone-11-1.png');
background-size: contain;
background-repeat: no-repeat;
background-position: center;
}
.iphone-mockup-content {
z-index: 5;
width: 100%;
height: 100%;
}
.iphone-mockup-content img {
width: 100%;
}
.passageWrapper {
position: sticky;
position: -webkit-sticky;
z-index: 10;
height: 70vh;
top: 0px;
background-image: url('https://www.donkey.de/wp-content/uploads/2020/08/iphone-11-1.png');
background-size: contain;
background-repeat: no-repeat;
background-position: center;
}
<div class="iphone-mockup">
<div class=passageWrapper></div>
<div class="iphone-mockup-container">
<div class="iphone-mockup-content">
<img src="https://www.donkey.de/wp-content/uploads/2020/07/donkey-agentur-cases-toni-gard-kampagne-true-6.jpg">
<img src="https://www.donkey.de/wp-content/uploads/2020/07/donkey-agentur-cases-toni-gard-kampagne-true-7.jpg">
<img src="https://www.donkey.de/wp-content/uploads/2020/07/donkey-agentur-cases-toni-gard-kampagne-true-6.jpg">
<img src="https://www.donkey.de/wp-content/uploads/2020/07/donkey-agentur-cases-toni-gard-kampagne-true-7.jpg">
<img src="https://www.donkey.de/wp-content/uploads/2020/07/donkey-agentur-cases-toni-gard-kampagne-true-6.jpg">
<img src="https://www.donkey.de/wp-content/uploads/2020/07/donkey-agentur-cases-toni-gard-kampagne-true-7.jpg">
</div>
</div>
</div>
I'm facing a challenge: The content does not align properly at the beginning of the sticky element. I've tried numerous approaches without success. Does anyone have any suggestions or ideas?
Thank you kindly,
Rick