I have a fixed block element inside a container. On scrolling the fixed positioned element is going beyond the container. I understood fixed element will be positioned according to window vw. But is there any way to make sure fixed positioned element will get scrolled only upto container position. The fixed position element should not go beyond the container
The problem can be seen in the following.
https://codepen.io/anon/pen/dKLByX
I tried to fix the problem using the following:
if($(window).scrollTop()>1900){
$('.fixed-ct').css({'bottom':'200px','top':'auto'});
}else if($(document).scrollTop() <=100) {
$('.fixed-ct').css({'top':'10px','bottom':'auto'});
}else {
$('.fixed-ct').css({'top':'0px','bottom':'auto'});
}
but sometimes the fixed container is at end because of bottom 200px it should be at top using top:0px on scroll and it should be inside the container itself.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…