| 13 | } |
| 14 | |
| 15 | function intersectionCallback(changes) { |
| 16 | // Code below is simply an example. |
| 17 | var latestChange = changes[changes.length - 1]; |
| 18 | |
| 19 | var { |
| 20 | // Amp-ad width and height. |
| 21 | height: h, |
| 22 | width: w, |
| 23 | |
| 24 | // Position in the viewport. |
| 25 | x: vx, |
| 26 | y: vy, |
| 27 | } = latestChange.boundingClientRect; |
| 28 | |
| 29 | var { |
| 30 | // Visible width and height. |
| 31 | height: vh, |
| 32 | width: vw, |
| 33 | } = latestChange.intersectionRect; |
| 34 | |
| 35 | // Viewable percentage. |
| 36 | var viewablePerc = ((vw * vh) / (w * h)) * 100; |
| 37 | |
| 38 | console.log(viewablePerc, w, h, vw, vh, vx, vy); |
| 39 | } |
| 40 | |
| 41 | function dummyCallback(changes) { |
| 42 | console.log(changes); |