Home > Software design >  How can I move the page along with all the elements inside?
How can I move the page along with all the elements inside?

Time:12-26

I need to move the entire html tag, let's say 100px to the right, along with all child nodes. But this is not possible due to the existence of fixed positioned elements. Is it possible to somehow move the viewport without moving the entire page to the iframe?

Now I do it by adding padding to html tag.

CodePudding user response:

unfortunately, position: absolute means that it is out of normal flow of html nodes, thus you cant.

CodePudding user response:

One option using javascript if you want to move the whole page

  window.scroll(100, 0);
  // OR
  window.scrollBy(100, 0);

to make this work make sure you don't set body style to overflow: hidden.

Alternatively, you could consider using a transform on the body element to achieve the desired effect.

like this:

   document.body.style.transform = 'translateX(100px)';
  • Related