【每日一练】76—一款非常有创意的删除按钮动画效果

每日一练1年前 (2023)发布 admin
2,263 0

坚持写100小项目的练习,真的不是一件容易的事情,我虽然没有保持每日更新,但是也基本保证了两三天更新一次。
但是时间总是很魔幻,不知不觉中,我们来到【每日一练】的76练的小项目现场,现在,就让我们一起来看一些今天的小练习吧。

【每日一练】76—一款非常有创意的删除按钮动画效果

看完了小练习的最终效果,我们再来看一下,它的实现代码

HTML:

<!DOCTYPE html>
<html>
<head>
<title>【每日一练】76—一款非常有创意的删除按钮动画效果</title>
</head>
<body>
<a href=”#” class=”btn”><span></span><text>Delete</text></a>
<script>
let btn = document.querySelector(‘.btn’);
btn.onclick = function(){
btn.classList.toggle(‘active’);
}
</script>
</body>
</html>

CSS:

*
{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: ‘Poppins’, sans-serif;
}
body
{
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #222;
}
a
{
position: relative;
height: 50px;
min-width: 160px;
background: #333;
color: #fff;
text-decoration: none;
display: flex;
justify-content: center;
align-items: center;
border-radius: 4px;
overflow: hidden;
transition: 0.5s;
box-shadow: 0 5px 20px rgba(0,0,0,0.15);
}
a.active
{
background: #2196f3;
}
a span
{
position: absolute;
left: 40px;
width: 18px;
height: 20px;
display: inline-block;
background: #fff;
margin-right: 10px;
border-bottom-left-radius: 3px;
border-bottom-right-radius: 3px;
transition: 0.5s;
}
a:hover span
{
transform: scale(2) rotate(60deg) translateY(10px);
}
a.active span
{
left: 50%;
transform: translateX(-50%) rotate(-45deg);
border-radius: 0;
width: 20px;
background: transparent;
border-left: 2px solid #fff;
border-bottom: 2px solid #fff;
height: 10px;
}
a span::before
{
content: ”;
position: absolute;
top: -3px;
width: 100%;
height: 2px;
background: #fff;
box-shadow: 12px -2px 0 #333,
12px -3px 0 #333,
15px -1px 0 #333,
6px -2px 0 #fff;
transition: 0.5s;
}
a.active span::before,
a.active:hover span::before
{
transform: scale(0);
}
a:hover span::before
{
transform: rotate(-90deg) translateX(50%) translateY(-10px);
}
a text
{
position: absolute;
right: 40px;
transition: 0.5s;
}
a:hover text,
a.active text
{
transform: translateX(-50px)  translateY(-5px) scale(0);
}

© 版权声明

相关文章

暂无评论

暂无评论...