I'm currently working on implementing a hover effect for an SVG rect embedded in HTML. The transition I've set up is not smooth, and the opacity values seem to be inconsistent during the animation.
My browser of choice is Firefox. The rect I'm working with has a fill color of pure red (#FF0000). Initially, its opacity is set to 0.1, which increases to 1 on hover. To monitor the transition's progress, I recorded a video where I noted the changes in the rect's red
value at different intervals. Given that the rect is positioned on a black background, I believe the red
value should reflect the overall opacity of the shape. Ideally, the transition should smoothly go from a red value of approximately 25 (255 * 0.1) to 255 (255 * 1). However, in reality, the actual transition ranges between a red value of 23 and 234. This inconsistency might be attributed to limitations in my recording software.
During the hovering action over the rect:
- The initial red value of the rect is 23
- Upon hover, the rect immediately disappears with a red value of 0
- The red value then transitions to 26
- Suddenly, there's a jump to a red value of 100
- Another fade occurs to reach a red value of 140
- This process ends with a jump to a final red value of 234
When the mouse moves away from the rect, the following sequence unfolds:
- The rect fades to a red value of 102
- An abrupt jump back to a red value of 45 follows
- Another fade brings it down to a red value of 10
- Lastly, another sudden jump results in a final red value of 23
Two key points confuse me. Firstly, why does the opacity fluctuate so drastically? Secondly, why does the opacity drop all the way to 10
(as seen in step 9), instead of stopping at 23? How can these issues be rectified?
Here is the code snippet I am using:
<html>
<head>
<title>Opacity transition test</title>
<style>
body > svg {
background: black;
}
#the-rect {
opacity: 0.1;
transition: opacity 1s linear;
}
#the-rect:hover {
opacity: 1;
}
</style>
</head>
<body>
<svg width="500" height="500">
<rect id="the-rect" x="0" y="0" width="250" height="250" fill="#FF0000"/>
</svg>
</body>
</html>