Skip to content
Advertisement

Function Launches before reaching the viewport when passing Arguments?

my question was closed because many people think it is associated with this question Why is the method executed immediately when I use setTimeout? I read all the answers but it doesn’t work for me and second, the question doesn’t contain any explanation to the question I asked: “why it’s not working when I am passing arguments? so can you guys please look thoroughly and lemme know”

Any help is highly appreciated 🙂

Again I am creating a scroll-based Typing effect using GSAP (Scroll trigger Plugin) and Typed Js (For typing effect) the thing is that the code works as desired when the function is directly attached to the OnEnter Property but when I pass class names as arguments in the external function the function gets launched (check Console by uncommenting the code) once the page reloads and doesn’t respond to the OnEnter property.

Can anyone tell me why it’s not working when I am passing arguments?

JavaScript
JavaScript
JavaScript

Advertisement

Answer

It’s because you are passing return value of function hello in onEnter callback.

You can use bind to bind argument to callback function

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement