admin管理员组

文章数量:1297018

As I learned that once you have set rootMargin:"0px", it means that the effect will be produced when the element you have selected has been pleted visible on screen and have 0px of margin with respect to the viewport or any relative.

In threshold property, it has values from 0% to 100% also denoted as 0 to 1. It means that if the value is 1, the callback will run once the element is 100% visible on the viewport.

Please highlight the differences between them.

As I learned that once you have set rootMargin:"0px", it means that the effect will be produced when the element you have selected has been pleted visible on screen and have 0px of margin with respect to the viewport or any relative.

In threshold property, it has values from 0% to 100% also denoted as 0 to 1. It means that if the value is 1, the callback will run once the element is 100% visible on the viewport.

Please highlight the differences between them.

Share Improve this question edited Sep 27, 2020 at 23:36 Zach Saucier 26k12 gold badges97 silver badges159 bronze badges asked Sep 27, 2020 at 12:30 Ibad ShaikhIbad Shaikh 3,5565 gold badges22 silver badges31 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

rootMargin is the rectangular bounding box around your root that you can adjust to trigger intersections. By default, this is your viewport. Use this to trigger an intersection when an element is within a certain area of the root i.e. trigger when my observed element reaches 25% of the viewport or 50px of the viewport. Values can be % or px. i.e. rootMargin: '0px 0px -50px' or rootMargin: '0px 0px -25%'.

threshold is the percentage of the observed element within the root. Use this to trigger an intersection when a percentage of the observed element is within the root i.e. trigger when 65% of my element is within the viewport (root). Values are % based between 0 and 1. i.e. threshold: .65

JSFiddle Demo

本文标签: