gpt4 book ai didi

javascript - 我想让图标在点击外部时向后旋转

转载 作者:太空宇宙 更新时间:2023-11-04 09:50:49 25 4
gpt4 key购买 nike

此代码用于在单击该图标时将箭头向上旋转。我想在单击图标外侧时将其旋转回来,我也想在单击图标并单击图标外侧时重复此过程图标。

<html>
<head>
<link rel="stylesheet" type="text/css" href="troll.css">
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../project/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="../project/style.css" />
<link rel="stylesheet" type="text/css" href="../project/font-awesome-4.2.0/css/font-awesome.min.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>
function rotate(){
document.getElementById("me").className="spinner fa fa-caret-down";
}
</script>
</head>
<body>
<i onclick="rotate()" id="me" class=" fa fa-caret-down "></i>
</body>
</html>

关联的CSS:

.spinner {
-webkit-animation:spin 0.5s linear 1;
-moz-animation:spin 0.5s linear 1;
animation:spin 0.5s linear 1;
animation-fill-mode: forwards;
}
@keyframes spin {
0% {
transform: rotate(0);
}
100% {
transform: rotate(180deg);
}
}
-webkit-keyframes spin {
0% {
transform: rotate(0);
}
100% {
transform: rotate(180deg);
}
}

最佳答案

试试这个

function rotate(e){
document.getElementById("me").className="spinner in fa fa-caret-down";
e.stopPropagation();
}

function resetRotation(){
document.getElementById("me").className="spinner out fa fa-caret-down";
}

document.addEventListener('click', resetRotation);
.spinner {
transition: all 0.5s linear;
}

.spinner.in{
transform: rotate(180deg);
}
.spinner.out{
transform: rotate(0deg);
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
<i onclick="rotate(event)" id="me" class="spinner fa fa-caret-down "></i>

关于javascript - 我想让图标在点击外部时向后旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39114116/

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