1 Star 6 Fork 2

tcsnzh / 法律工具页

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
common_at_last.js 1.13 KB
一键复制 编辑 原始数据 按行查看 历史
TcSnZh 提交于 2022-10-16 12:21 . v1.3.5 美化button,优化引入结构
// button 涟漪效果
(function () {
function createRipple(event) {
const button = event.currentTarget;
const circle = document.createElement("span");
const diameter = Math.max(button.clientWidth, button.clientHeight);
const radius = diameter / 2;
circle.style.width = circle.style.height = `${diameter}px`;
circle.style.left = `${event.pageX - button.offsetLeft - radius}px`;
let offsetTop = button.offsetTop
let eventY = (function () {
let difPageY = Math.abs(event.pageY - offsetTop)
let difClientY = Math.abs(event.clientY - offsetTop)
return difPageY > difClientY ? event.clientY : event.pageY;
})()
circle.style.top = `${eventY - offsetTop - radius}px`;
circle.classList.add("ripple");
const ripple = button.getElementsByClassName("ripple")[0];
if (ripple) {
ripple.remove();
}
button.appendChild(circle);
}
const buttons = document.getElementsByTagName("button");
for (const button of buttons) {
button.addEventListener("click", createRipple);
}
})()
HTML
1
https://gitee.com/tcsn_site/proletariat-legal-tools-page.git
git@gitee.com:tcsn_site/proletariat-legal-tools-page.git
tcsn_site
proletariat-legal-tools-page
法律工具页
main

搜索帮助