How to check element is in viewport in angular 2?. I have tried with many npm packages. But not working. How to check the element is in viewport?. I want to call API on page scroll if element is in viewport?
I have three tabs. I have to check if tab is active and element is in viewport. How to check?
I didn't use this for a while, but might be what you're looking for (refactor it to fit your needs):
example use:
I used 'jQuery-viewport-checker' to perform various tasks if elements are on viewport. It worked for me. This may help you:
Follow this if you don't have "jQuery" working in your angular 2 project: https://stackoverflow.com/a/42295505/7532440
You'll have to install the 'jQuery-viewport-checker' using 'Bower' and add it to 'Scripts' in 'angular-cli.json' file like the way you have installed the 'jQuery' in the link I have provided.
cmd:
in 'angular-cli.json':
Now you can use 'jQuery-viewport-checker'
More info on: https://github.com/dirkgroenen/jQuery-viewport-checker
Your app.component.ts will look like this:
Here class 'visible' will be added on ".dummy" class in an element once it's in the ViewPort. You should explore it more(other parameters) according to your need Accordingly you can code your HTML. I Hope it helps.
Update:
If it gives error try the following (as these worked for the author of the question):
1): try changing the port ng serve --port 4200 to 4208 (or any other port)
2): put viewport checker code inside document ready like this:
and remove offset: [100]