I created a fingerprint scanner animation in CSS, but I encountered an issue where the scanner animation does not stay in place and instead follows the animation of the scanning board. For more details, I have attached the my codesandbox link below.
I would really appreciate your help, thank you.
2
Answers
The top image moves with the scan because it is created using a CSS animation that animates the height of the image from 0% to 100% and back to 0% over a duration of 4 seconds. This animation is applied to the pseudo-element
::before
of the.scan .retina
element using the animate keyframe rule.The
::before
pseudo-element is positioned absolutely with respect to the.scan .retina
element, and its height is animated to fill the entire height of the.scan .retina
element.Since the
::before
pseudo-element is layered above the background image of the.scan .retina
element, the appearance of the background image appears to move along with the animation.background-position: center
uses the element height to calculate the central position for the background image. You are animating the element’s height so the central position is constantly changing. You will need to set a fixed location forbackground-position
.Setting the background image to be 75px from the top seems to be the right position.