Skip to content

Tag: addeventlistener

React Using addEventListener(“scroll”, function()) and useState shows no transition

I want to change background color of navigation gradually with transition like this Article.js Article.css When I run these, class name ‘active’ is added to the [div] but its background color is changed quickly from rgb(248, 249, 250) to rgb(255, 255, 255). I think this is because addEventListener changes isScrolling every scroll and rerenders the [div] element and its children.

addEventListener to all buttons using forEach

I am trying to addEventListener to all of my buttons. This is my first time using addEventListener and it is not running the usergetNumber function which should display a random number when any button is clicked. Answer From top to bottom. There’s already a function usergetNumber() { … } declaration in addEventListener(). It’s a function declaration not a callback here.