Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Can anyone tell me a JS listener to be used when a user scrolls in a certain textbox with cross-browser compatibility?

1 Answer

0 votes
by (19.7k points)

Below is the JQuery code to add scroll listening to a number of CSS-selector elements:

// what should we do when scrolling occurs

var runOnScroll =  function(evt) {

  // not the most exciting thing, but a thing nonetheless

  console.log(evt.target);

};

// grab elements as array, rather than as NodeList

var elements = document.querySelectorAll("...");

elements = Array.prototype.slice.call(elements);

// and then make each element do something on scroll

elements.forEach(function(element) {

  window.addEventListener("scroll", runOnScroll, {passive: true});

});

Interested in Java? Check out this Java Certification by Intellipaat. 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked May 9, 2021 in Java by sheela_singh (9.5k points)
0 votes
1 answer
asked May 9, 2021 in Java by sheela_singh (9.5k points)

Browse Categories

...