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 badges1 Answer
Reset to default 9rootMargin 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
本文标签:
版权声明:本文标题:javascript - What is the main difference between rootMargin & threshold in Intersection Observer API? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741647847a2390294.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论