Marian Rick Marian Rick - 3 months ago 29
Javascript Question

Detect if is in viewport using verge

I consider using verge by ryanve to detect wether some elements appear to be inside the current viewport.

As I did not find any tutorials on how to use verge, I wanted to try it out for myself. As a very basic example I want to use

to detect wether my image is inside the viewport or not and manipulate it.

I have tried a basic example, which does not work:

if(verge.inViewport(target)) {
target.show();
}


JSFIDDLE DEMO

Answer

The code does actually work, like stated out by @AdamAzad in the comments:

if(verge.inViewport(target)) {
  target.show();
}