gpt4 book ai didi

html - 用户点击时 Font Awesome 翻译或转换

转载 作者:太空宇宙 更新时间:2023-11-04 00:38:41 26 4
gpt4 key购买 nike

美好的一天!我正在尝试使用 Font Awesome 5 制作一个固定的 float 操作按钮,当用户单击大按钮时,它会将 Font Awesome 转换或转换为另一个 Font Awesome Logo 。

这是 https://jsfiddle.net/4eLq3dj0/ 的 fiddle 到目前为止我已经尝试过了。我还想让它绕着底部旋转,所以我使用了另一根线。

HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.min.css" rel="stylesheet">
<link rel="stylesheet" href="">
</head>

<body>
<div class="button">
<div class="icons">
<button href="#" class="floating-btn">
<i class="fas fa-plus icon-default "></i>
<i class="fas fa-times icon-hover"></i>
</button>
</div>
</div>
</body>
</html>

CSS

.floating-btn{
width: 80px;
height: 80px;
background: #f5af09;
display: flex;
align-items: center;
justify-content: center;
text-decoration: none;
border-radius: 50%;
color: #ffffff;
font-size: 40px;
box-shadow: 2px 2px 5px (0,0,0,0.25);
position: fixed;
right: 20px;
bottom: 20px;
transition: background 0.25s;
outline: blue;
border: none;
cursor: pointer;

}
.button .icons {
position: relative;
display: flex;
justify-content: center;
align-items: center;
margin: 0 2.3rem 0 0;
width: 1.25rem;
height: 2.6rem;
}

.button .icons i {
position: absolute;
top: 5;
left: 5;
display: block;
}

.floating-btn:active{
background:#007D63;
}

.button .icons .icon-hover {
transition: opacity 0.3s, transform 0.3s;
transform: rotate(-180deg) scale(0.5);
opacity: 0;
}

.button:active {
transform: scale(1.2);
box-shadow: 20px 15px rgba(0, 0, 0, 0.15);
}

.button:active .icon-hover {
transform: rotate(0deg) scale(1);
opacity: 1;
}

.button:active .icon-default {
transform: rotate(180deg) scale(0.5);
opacity: 0;
}

最佳答案

这是您要实现的目标吗?悬停:

.floating-btn {
width: 80px;
height: 80px;
background: #f5af09;
text-decoration: none;
border-radius: 50%;
color: #ffffff;
font-size: 40px;
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.25);
display: flex;
align-items: center;
justify-content: center;
position: fixed;
right: 20px;
bottom: 20px;
transition: background-color 0.25s ease-out;
border: none;
cursor: pointer;
}

.floating-btn:hover {
background-color: red;
}

.floating-btn i {
transition: transform 0.25s cubic-bezier(.4, 0, .2, 1);
}

.floating-btn:hover i {
transform: rotate(45deg);
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.min.css" rel="stylesheet" />

<div class="button">
<div class="icons">
<button href="#" class="floating-btn">
<i class="fas fa-plus"></i>
</button>
</div>
</div>

点击:

document.querySelector('.floating-btn').addEventListener('click', function(e) {
e.target.closest('button').classList.toggle('clicked');
})
.floating-btn {
width: 80px;
height: 80px;
background: #f5af09;
text-decoration: none;
border-radius: 50%;
color: #ffffff;
font-size: 40px;
box-shadow: 0 1px 3px 0 rgba(0,0,0,.2), 0 1px 1px 0 rgba(0,0,0,.14), 0 2px 1px -1px rgba(0,0,0,.12);
display: flex;
align-items: center;
justify-content: center;
position: fixed;
right: 20px;
bottom: 20px;
transition: background-color 0.25s ease-out, box-shadow 0.25s ease-out;
border: none;
cursor: pointer;
outline: none;
}
.floating-btn:hover {
box-shadow: 0 4px 5px -2px rgba(0,0,0,.2), 0 7px 10px 1px rgba(0,0,0,.14), 0 2px 16px 1px rgba(0,0,0,.12);
}


.floating-btn.clicked {
background-color: red;
}

.floating-btn i {
transition: transform 0.25s cubic-bezier(.4, 0, .2, 1);
}

.floating-btn.clicked i {
transform: rotate(315deg);
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.min.css" rel="stylesheet" />

<div class="button">
<div class="icons">
<button href="#" class="floating-btn">
<i class="fas fa-plus"></i>
</button>
</div>
</div>

关于html - 用户点击时 Font Awesome 翻译或转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58813742/

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