flowforfrank / webtips

https://webtips.dev
1 stars 0 forks source link

webtips/cypress/check-if-element-is-in-viewport #19

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

How to Check if Element is in Viewport in Cypress - Webtips

To check if an element is in the viewport in Cypress, we can add a custom 'inViewport' assertion to Chai using the support folder.

https://www.webtips.dev/webtips/cypress/check-if-element-is-in-viewport?utterances=eb663369dcfd1ad78f89f9e1VmVHPDPzhWrzMgDos1HC7IqgeYuhp1J16z64EbMskY5%2BUVN%2F7Ohyp2Nnx14BwV9bG%2Bsatto2df4mU0OtzxnVJafiV0FOxX6QSiKzd6sYECPQbNhL7L3heeGSlss%3D

dwjohnston commented 1 year ago

Note that the standard is.visible assertion might be all you need.

dwjohnston commented 1 year ago

There is a slight bug in your code here, you also need to check that the element is not out the top, with && rect.bottom >= 0