Answer the question
In order to leave comments, you need to log in
How to fix an element on a page without fixed?
I did it using jquery, but when scrolling, the element jumps from the old position to the new one. How can I get rid of this twitching. fixed is not suitable, because pulls the element from the parent.
Answer the question
In order to leave comments, you need to log in
This is the code that should be:
$(window).scroll(function(){
$("#your_block").css({"margin-top":$(this).scrollTop()});
});
One of the options. Attach a function to scroll events. Where top is the scroll top.
var topOffset = $("#map-search").offset();
function mapSearchScroll(top,topOffset){
if(top > topOffset.top){
$("#map-search").css({
"-webkit-transform":"translate(0," + (top - topOffset.top) +"px)",
"-ms-transform":"translate(0," + (top - topOffset.top) +"px)",
"transform":"translate(0," + (top - topOffset.top) +"px)"
});
}else{
$("#map-search").css({
"-webkit-transform":"translate(0,0)",
"-ms-transform":"translate(0,0)",
"transform":"translate(0,0)"
});
}
}
Fixing an element on the page implies its isolation. What does "pulls an element from its parent" mean?
I believe that the block becomes sticky, then you must either put it on jquery animate with a position, or make the positions as similar as possible both before and after. And it's hard to say without code examples or screenshots.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question