jQuery(window).scroll(function(){ var $sections = $('section'); $sections.each(function(i,el){ var top = $(el).offset().top-300; }) }); 

Translate 4 line to native js please.

Closed due to the fact that the essence of the question is incomprehensible by the participants Igor , 0xdb , yolosora , iluxa1810 , entithat Nov 13 Nov '18 at 16:04 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    What for? This code does nothing useful. - Igor
  • This is a clipping from the code. As I understand it, it shows the distance from the top of the page to the section. - kekik
  • Why ask the same question several times? - Grundy
  • The question seems to be simple, but there is no answer. To find out how this line will be in native JavaScript. - kekik
  • 3
    Why, instead of editing that question, did you just ask the same thing, and again without formatting? - Grundy

1 answer 1

The fourth line on native JavaScript will look like this
var top = element.offsetTop;
var x = top - 300;

  • one
    As many as two variables per subtraction. - Qwertiy