gpt4 book ai didi

css - onmouseenter KeyFrame 只工作一次

转载 作者:太空宇宙 更新时间:2023-11-03 17:29:28 25 4
gpt4 key购买 nike

如您所见,以下动画在您第一次将鼠标悬停在正方形上时会起作用,但在第一次后它不再起作用,这就是我的目标:

function js1(x){
x.style.animation="anime 1s";
}

function js2(x){
x.style.animation="anime1 1s";
}
#tria {
width: 0;
height: 0;
border-style: solid;
border-width: 50px 0 50px 200px;
border-color: transparent transparent transparent #007bff;
position:absolute;
top:200px;
}

#tria2 {
width: 0;
height: 0;
border-style: solid;
border-width: 50px 200px 50px 0;
border-color: transparent #007bff transparent transparent;
position:relative;
float:right;
top:200px;
}

@Keyframes anime{
from {left: 0;}
to {left: 200px;}
}
@Keyframes anime1{
from {left: 0;}
to {left: -200px;}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Site 2</title>
<link href="styles.css" rel="stylesheet" type="text/css">
<script src="triascript.js"></script>
</head>

<body>

<div id="tria" onmouseenter="js1(this)"></div>
<div id="tria2" onmouseenter="js2(this)" ></div>






</body>
</html>

其他例子:

https://jsfiddle.net/sergiureznicencu/4dyq1dgk/

最佳答案

尝试在 mouseleave 之后重置它:

JS:

function reset(x){
x.style.animation = "";
}

HTML:

<div id="tria" onmouseenter="js1(this)" onmouseleave="reset(this)"></div>
<div id="tria2" onmouseenter="js2(this)" onmouseleave="reset(this)"></div>

另一种方法是使用 timeOut:

JS

function js1(x){
x.style.animation="anime 1s";
setTimeout(function() {x.style.animation = "";}, 1000);
}

function js2(x){
x.style.animation="anime1 1s";
setTimeout(function() {x.style.animation = "";}, 1000);
}

HTML:

<div id="tria" onmouseenter="js1(this)"></div>
<div id="tria2" onmouseenter="js2(this)" ></div>

https://jsfiddle.net/4dyq1dgk/4/

关于css - onmouseenter KeyFrame 只工作一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30873112/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com