Greetings. I had difficulty writing a jquery script.

$(document).ready(function(){ $(window).scroll(function(){ var bo = $('.header').scrollTop(); $('body').append(bo); }) }) 

when scrolling the page displays 0, and if you write like this

 $(document).ready(function(){ $(window).scroll(function(){ var bo = $(window).scrollTop(); $('body').append(bo); }) }) 

then everything is fine, but I need it from the element. Thank you in advance.

  • > but I need exactly from the element What is "from the element" you need? - Deonis
  • Throw an example of your markup on, take the wrong scrollTop element, I suspect that you need to watch for its parent ... - Yura Ivanov
  • @Yura Ivanov, not in the markup deal. .scrollTop () and .scrollLeft () give the value of scrolling elements, but in the TS example, not the element with the class .header scrolls , but the page as a whole. The question should be more precisely formulated. Or rather, to understand that in the process of scrolling you need to get it. - Deonis
  • @Deonis for a div with oveflow: scroll will also be scrollTop and scrollLeft. it is quite possible that we are talking about this too. - Yura Ivanov
  • @Yura Ivanov, right, but in this case it is necessary to hang the event on this element , but not on the window. - Deonis