I need to pin an image that spans the entire width. The following things did not work for me
- clip: this requires an absolute position, so the elements of the block do not flow below
- background-position: it does not loop when the enlarged part is enlarged when magnified, and vice versa.
- wrapper: the height of the wrapper depends on the width of the browser, so its value should be dynamic.
I used js with setinterval 1 millisecond. so the wrapper height is constantly updated. works fine in all scenarios, but setinterval is bad practice. so please suggest a cleaner way to implement this.
document.onreadystatechange = setInterval(function () {
if (document.readyState == "complete") {
brow_width = document.body.clientWidth;
var h1 = (brow_width/7);
document.getElementById("clip1").style.opacity = "1";
if(brow_width > 700){
document.getElementById("clip1").style.height= h1;
}
else{
document.getElementById("clip1").style.height= 110;
}
var h2 = (brow_width/33.33);
document.getElementById("clip2").style.opacity = "1";
if(brow_width > 700){
document.getElementById("clip2").style.height= h2;
document.getElementById("banner2").style.top= h2 - brow_width*0.35;
}
else{
document.getElementById("clip2").style.height= 21;
document.getElementById("banner2").style.top= -220;
}
}
},1);
<div id="clip1">
<img id="banner1" src="banner.jpg">
</div>
<div id="clip2">
<img id="banner2" src="banner.jpg">
</div>
source
share