Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jump at end of CSS transition

When I hover over the div, the .note span fades in. After it fades in, the font-weight seems to suddenly increase (it becomes bolder). I realize that in the fiddle there is no image, but it is not required to see my issue.

Html:

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="style.css">
    <script src="script.js"></script>
    <title>Cool Effect</title>
</head>
<body>

    <div class="imageHolder">
        <img src="picture1.jpeg">
        <span class="note">Hello!</span>
    </div>

</body>
</html>

CSS:

.imageHolder {
    position: relative;
    top:300px;
    left: 300px;
    width: 300px;
    height: 250px;
    text-align: center;
    overflow: hidden;
    background-color: black;
}

.note {
    position: absolute;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    border: 2px solid white;
    padding: 8px;
    color: white;
    font-size: 24px;
    opacity: 0;
    -webkit-transition: opacity 0.5s;
    transition: opacity 0.5s;
}

img {
    width: 300;
    opacity: 1;
    height: 250px;
}

.imageHolder:hover .note {
    opacity: 1;
}

Thanks.

like image 373
George Avatar asked Sep 27 '22 06:09

George


1 Answers

Using a 3d transform (ie. using hardware acceleration) fixes lots of these rendering issues.

.note {
    ...
    -webkit-transform: translate3d(-50%, -50%, 0);
    transform: translate3d(-50%, -50%, 0);
    ...
}

This is well documented

DEMO


Alternatively, this also seems to work for your example and may have better browser support...

.note {
    ...
    -webkit-backface-visibility: hidden;
    ...
}

DEMO

like image 179
Turnip Avatar answered Oct 06 '22 03:10

Turnip