I want to make background of a div fixed so switching div will gave an effect of switching images like on phone screen. It is like worsen version of this: https://www.android.com/versions/nougat-7-0/
Fiddle link.
I am trying in this way:
.main {
min-height: 1000px;
}
.col1 {
width: 29.9%;
min-height: 800px;
display: inline-block;
float: left;
}
.col2 {
width: 70%;
min-height: 800px;
display: inline-block;
}
.row1 .col1 {
background: rgba(238, 238, 34, 0.3) url("https://icons.iconarchive.com/icons/graphicloads/100-flat-2/256/24-hours-phone-icon.png") !important;
background-position: left !important;
background-repeat: no-repeat !important;
background-size: contain !important;
background-attachment: fixed !important;
}
.row2 .col1 {
background: rgba(238, 238, 34, 0.3) url("https://icons.iconarchive.com/icons/graphicloads/100-flat-2/256/abs-icon.png") !important;
background-position: left !important;
background-repeat: no-repeat !important;
background-size: contain !important;
background-attachment: fixed !important;
}
.row3 .col1 {
background: rgba(238, 238, 34, 0.3) url("https://icons.iconarchive.com/icons/graphicloads/100-flat-2/256/arrow-down-icon.png") !important;
background-position: left !important;
background-repeat: no-repeat !important;
background-size: contain !important;
background-attachment: fixed !important;
}
<div class="main">
<div class="row1">
<div class="col1">
Col1
</div>
<div class="col2">
Col2
</div>
</div>
<div class="row2">
<div class="col1">
Col1
</div>
<div class="col2">
Col2
</div>
</div>
<div class="row3">
<div class="col1">
Col1
</div>
<div class="col2">
Col2
</div>
</div>
</div>
But there is no luck since picture is always bigger than div and not inside div as i need and even more problem is that when browser size is changing a background position is changing too.
I know because of background attachment fixed, so it is looking a hole viewport and not a div only, but is there any workaround to achieve this?
So goal is to have background image nicely on center BUT fixed position inside this mother div, so when scrolling an switching effect will be given. When changing browser viewport picture is always the same size at the center of mother div.
I know about scroll magic, but i just want something more "natural" trough CSS or might minimum JS code.