A
A
Alexander Sinitsyn2015-10-25 21:07:32
css
Alexander Sinitsyn, 2015-10-25 21:07:32

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

4 answer(s)
I
Ilyusha Prokopiev, 2015-10-25
@iliapro

This is the code that should be:

$(window).scroll(function(){
    $("#your_block").css({"margin-top":$(this).scrollTop()});
});

A
Artem, 2015-10-26
@Paramount1987

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)"
    });
  }

}

A
Alexander Wolf, 2015-10-25
@mannaro

Fixing an element on the page implies its isolation. What does "pulls an element from its parent" mean?

E
Evgeny Danilov, 2015-10-25
@danilovevgen

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 question

Ask a Question

731 491 924 answers to any question