When a certain value of scroll is reached in a block, some code must be executed. But it does not work. Why?

var scroll = $('#block').scrollTop(); if (scroll == 100) { alert('123'); } 

https://jsfiddle.net/9hk2gngd/

  • one
    you will never get to 100 at jsfiddle.net/9hk2gngd/1 - splash58
  • thank! now clear - Clark
  • @ splash58, the answers - in the answers. - Qwertiy

1 answer 1

 function myFunction() { var elmnt = document.getElementById("myDIV"); var x = elmnt.scrollLeft; //горизонтальный var y = elmnt.scrollTop; //вертикальный if (y > 100) { // 100 - значение в пикселях (если больше делать что-то) } }