Move to end of CSS transition

When I hover over the div, the .note range disappears. After it fades out, the font weight seems to suddenly increase (it gets bolder). I understand that there is no image in the fiddle , but I don't need to see my problem.

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;
}

      

Thank.

+3


source to share


2 answers


Using a 3D transform (i.e. using hardware acceleration) fixes many of these rendering issues.

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

      

It's well documented

DEMO




Alternatively, this also works for your example and may have better browser support ...

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

      

DEMO

+4


source


Please note the following changes:

.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.1s;             <--
    transition: opacity 0.1s;                     <--
}

      



Although the transition speed is slightly faster, it fixes the problem in the script.

0


source







All Articles