1 Star 7 Fork 3

杨不易呀/gitee-zhuangbi

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献度自定义样式.html 5.75 KB
一键复制 编辑 原始数据 按行查看 历史
杨不易呀 提交于 2024-05-14 11:02 . :art:新增贡献度自定义
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>个人网页</title>
<style>
body {
background-color: #fff;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
margin: 0;
padding: 0;
text-align: center;
color: #333;
}
h1 {
margin-top: 50px;
}
.graph {
margin-top: 30px;
display: inline-block;
font-size: 0; /* Remove white space between cells */
touch-action: none; /* Prevent scrolling while dragging on touch devices */
}
.graph-row {
display: block;
font-size: 0; /* Remove white space between cells */
}
.graph-cell {
width: 30px; /* Increase cell size */
height: 30px; /* Increase cell size */
margin: 1px;
display: inline-block;
background-color: #ebedf0; /* Light grey color similar to GitHub's contribution graph */
cursor: pointer; /* Add cursor pointer to indicate clickable */
}
.graph-cell.active {
background-color: #c6e48b; /* Green color similar to GitHub's contribution graph */
}
.reset-button {
margin-top: 20px;
padding: 10px 20px;
font-size: 16px;
background-color: #0366d6; /* GitHub's primary color for buttons */
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}
.reset-button:hover {
background-color: #0550ae; /* Darker shade of GitHub's primary color on hover */
}
</style>
</head>
<body>
<h1>我的 GitHub 贡献度</h1>
<div class="graph">
<!-- GitHub 贡献度功能报表 -->
<script>
// GitHub 贡献度功能报表的二维数组
var Led = [
[0,0,0,0,24,0,0,0,0,24,0,0,0,0,0,24,24,24,24,24,24,24,0,0,0,0,24,24,24,24,24,24,24,0,0,0,24,24,24,24,24,24,0,0,0,24,0,0,24,0,0,0,0,0],
[0,0,0,24,1,24,24,24,24,1,24,0,0,0,24,16,8,8,1,8,8,16,24,0,0,24,8,8,1,1,1,8,8,24,0,0,24,16,16,16,16,24,0,0,24,24,24,24,24,24,0,0,0,0],
[0,0,0,24,1,1,1,1,1,1,24,0,0,0,24,8,8,1,1,1,8,8,24,0,24,16,8,8,1,1,1,8,8,16,24,0,24,1,16,16,1,24,0,0,24,1,16,16,1,24,0,0,0,0],
[0,8,8,24,1,24,1,1,24,1,24,8,8,0,24,16,24,24,24,24,24,16,24,0,24,16,16,24,24,24,24,24,16,16,24,0,24,16,16,16,16,24,0,0,24,24,24,24,24,24,0,0,0,0],
[0,0,0,24,1,1,16,16,1,1,24,0,0,0,24,24,1,24,1,24,1,24,24,0,0,24,24,1,24,1,24,1,24,24,0,0,24,24,24,24,24,24,0,24,0,0,24,24,0,0,0,0,0,0],
[0,8,8,24,1,1,1,1,1,1,24,8,8,0,0,24,1,1,1,1,1,24,0,0,0,0,24,1,1,1,1,1,24,0,0,0,0,0,24,24,0,0,0,0,24,24,24,24,24,0,0,0,0,0],
[0,0,0,0,24,24,24,24,24,24,0,0,0,0,0,0,24,24,24,24,24,0,0,0,0,0,0,24,24,24,24,24,0,0,0,0,24,24,24,24,24,24,0,0,0,0,24,24,24,0,0,0,0,0]
];
// 遍历 Led 数组,在页面中生成对应的方块并设置颜色
function createGraph() {
for (var i = 0; i < Led.length; i++) {
var row = document.createElement("div");
row.classList.add("graph-row");
for (var j = 0; j < Led[i].length; j++) {
var cell = document.createElement("div");
cell.classList.add("graph-cell");
if (Led[i][j] !== 0) {
cell.classList.add("active");
}
cell.addEventListener("mousedown", handleMouseDown);
cell.addEventListener("mouseenter", handleMouseEnter);
cell.addEventListener("mouseup", handleMouseUp);
row.appendChild(cell);
}
document.querySelector(".graph").appendChild(row);
}
}
// 创建重置按钮并添加点击事件
function createResetButton() {
var resetButton = document.createElement("button");
resetButton.innerText = "重置";
resetButton.classList.add("reset-button");
resetButton.addEventListener("click", function() {
var cells = document.querySelectorAll(".graph-cell.active");
cells.forEach(function(cell) {
cell.classList.remove("active");
});
});
document.body.appendChild(resetButton);
}
var isDragging = false; // Flag to track if mouse is currently being dragged
var currentColor = "#c6e48b"; // Default color to set when dragging
// Function to handle mouse down event on a cell
function handleMouseDown() {
isDragging = true;
toggleColor(this); // Toggle color of the cell when mouse is pressed down
}
// Function to handle mouse enter event on a cell (when mouse is dragged)
function handleMouseEnter() {
if (isDragging) {
toggleColor(this); // Toggle color of the cell when mouse is dragged over it
}
}
// Function to handle mouse up event on a cell
function handleMouseUp() {
isDragging = false;
}
// Function to toggle color of a cell
function toggleColor(cell) {
if (cell.classList.contains("active")) {
cell.classList.remove("active");
} else {
cell.classList.add("active");
}
}
createGraph(); // 调用函数创建贡献度图表
createResetButton(); // 调用函数创建重置按钮
</script>
</div>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yangbuyi/gitee-zhuangbi.git
git@gitee.com:yangbuyi/gitee-zhuangbi.git
yangbuyi
gitee-zhuangbi
gitee-zhuangbi
master

搜索帮助