0

I am new to CSS-Animation, so maybe the answer for you is easy. But I couldn't find an answer here yet.

I want an Element to start an animation on hover and then never end. It's for an art project because practically it doesn't make any sense.

What I have got is: A little circle, when on hover it starts getting bigger and bigger. And I want that animation to continue endlessly (or fake it like endlessly with transition: 100000s or sth like that).

Any idea how to manage that?

What I have got is this:

.circle{
  background-color: orange;
  border-radius: 10px;
  width: 20px;
  height: 20px;
  margin-top: 10%;
  margin-left: 50%;
  transition: 1000s;
}

.circle:hover{
  transform: scale(8000);
}

.circle:hover{
  transform: scale(8000);
}
<div class="circle"></div>

Thank you very much already.

4

3 回答 3

4

我将其更改.circle:hover为一个名为“circleAnimation”的新类。然后,我给圆圈一个 onmouseenter 事件,将它添加到类中(因为 JavaScript 只有一行,我将它直接输入到 onmouseenter 事件的值中)。

结果如下所示:

.circle {
    background-color: orange;
    border-radius: 10px;
    width: 20px;
    height: 20px;
    margin-top: 10%;
    margin-left: 50%;
    transition: 1000s;
}

.circleAnimation {
    transform: scale(8000);
}
<div class="circle" onmouseenter="event.target.classList.add('circleAnimation')"></div>

希望这有帮助!

于 2021-04-08T12:24:48.997 回答
2

我认为它可以帮助你。

.circle {
    background-color: orange;
    border-radius: 10px;
    width: 20px;
    height: 20px;
    margin-top: 10%;
    margin-left: 50%;
    transition: 1000s;
}

.animate {
    transform: scale(8000);
}
<div class="circle" onmouseenter="event.target.classList.add('animate')"></div>

您也可以使用onmouseover代替onmouseenter.

于 2021-04-08T12:28:10.727 回答
0

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
    <style>
        .circle{
            background-color: orange;
            border-radius: 10px;
            width: 20px;
            height: 20px;
            margin-top: 10%;
            margin-left: 50%;
            transition: 1s;
        }
    </style>
</head>
<body>
    <div class="circle" onmouseover="changeScale(this)"></div>
    <script>
        function changeScale(circle){
            circle.style.transform = 'scale(80)';
        }
    </script>
</body>
</html>

于 2021-04-08T12:38:23.327 回答