-1

So, I try to add the current window.pageYOffset value as a marginTop value for someone container on the page with onclick event. But it does not happen.

Also I want to admit, that there is no problem with adding a positive value of the window.pageYOffset to marginTop.

Here my code:

    let a = window.pageYOffset;

    const rightColumn = document.querySelector('.right-side__column');
    rightColumn.style.marginTop = '-' + a + 'px'; // in such way a in 
                                           // padding even equal to 0.

    // rightColumn.style.marginTop = a + 'px'; - work fine, the value is transfer normally.
Max Wolfen
  • 1,923
  • 6
  • 24
  • 42

1 Answers1

0

Instead of what you did, try using 0 - a + "px".

fig
  • 364
  • 2
  • 11