前言:哈喽,大家好,今天给大家分享html+css+js 绚丽效果!并提供具体代码帮助大家深入理解,彻底掌握!创作不易,如果能帮助到大家或者给大家一些灵感和启发,欢迎收藏+关注哦 💕
效果
原理解析
1.给每一个按钮添加一个点击事件,点击时在这个按钮中生成一个span元素。
2.生成的这个span元素做一个动画效果:
3.1秒后自动删除这个span元素。
代码,可复制查看效果
目录
html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<title>html+css+js 3D涟漪特效按钮</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<h1 style="text-align: center;color:#fff;margin-bottom: 50px;padding-top: 50px">html+css+js 3D涟漪特效按钮</h1>
<div class="btn-box">
<button>点赞</button>
<button>关注</button>
<button>收藏</button>
<button>转发</button>
</div>
<script type="text/javascript">
// 获取所有按钮对象
const btns=document.querySelectorAll("button");
// 循环所有按钮,并为每一个按钮添加点击事件
btns.forEach(btn=>{
btn.addEventListener("click",e=>{
// 创建span元素,并设置其位置为鼠标点击的位置
let span=document.createElement("span");
span.style.left=e.offsetX+"px";
span.style.top=e.offsetY+"px";
// 将span元素添加到按钮标签里
btn.appendChild(span);
// 1秒后删除span元素
setTimeout(() => {
span.remove();
}, 1000);
})
})
</script>
</body>
</html>
css
*{
/* 初始化 */
margin: 0;
padding: 0;
}
body{
/* 100%窗口高度 */
height: 100vh;
/* 渐变背景 */
background: linear-gradient(200deg,#80d0c7,#13547a);;
}
.btn-box{
width: 500px;
margin: 0 auto;
/* 弹性布局 */
display: flex;
/* 横向排列 */
flex-direction: row;
/* 允许换行 */
flex-wrap: wrap;
/* 平均分配宽度给每一个子元素 */
justify-content: center;
}
.btn-box button{
/* 相对定位 */
position: relative;
border: none;
background: linear-gradient(to right,#52d1c2,#1ab3a1);;
width: 200px;
height: 60px;
margin: 20px 20px;
font-size: 18px;
color: #fff;
/* 字间距 */
letter-spacing: 3px;
border-radius: 30px;
/* 阴影 */
box-shadow: 3px 5px 10px rgba(0,0,0,0.1);
cursor: pointer;
/* 这里加个溢出隐藏 */
overflow: hidden;
}
.btn-box button span{
/* 绝对定位 */
position: absolute;
/*width: 30px;*/
/*height: 30px;*/
background-color: #fff;
border-radius: 50%;
transform: translate(-50%,-50%);
/* 设置元素不对指针事件做出反应 */
pointer-events: none;
/* 执行动画 */
animation: animate 1s ease;
}
/* 定义动画 */
@keyframes animate {
from{
width: 0;
height: 0;
opacity: 0.5;
}
to{
width: 400px;
height: 400px;
opacity: 0;
}
}
.btn-box button:hover{
box-shadow: 3px 5px 10px rgba(0,0,0,0.2);
}
到此这篇文章就介绍到这了,更多精彩内容请关注本人以前的文章或继续浏览下面的文章,创作不易,如果能帮助到大家,希望大家多多支持宝码香车~💕
更多专栏订阅推荐:
👍 html+css+js 绚丽效果
💕 vue
✈️ Electron
⭐️ js
📝 字符串
✍️ 时间对象(Date())操作