之前为了让谷歌浏览器里的书签放到博客 markdown 文件下,写过一个书签和 markdown 互转的小工具 parse-bookmark,当初也是为了能直接在博客中生成一个网址导航的页面,方便随时查找一些常用的网站。
2025年06月21日
之前为了让谷歌浏览器里的书签放到博客 markdown 文件下,写过一个书签和 markdown 互转的小工具 parse-bookmark,当初也是为了能直接在博客中生成一个网址导航的页面,方便随时查找一些常用的网站。
2025年06月21日
文本溢出处理是前端开发者必备的一个技能,很多时候,你无法预料到文本到底有多长,用手动的方式删除文本肯定是不现实,就需要自动的让多出的文字变省略号,所以掌握text-overflow很有必要。
text-overflow
2025年06月21日
本人一开始是做移动端原生开发的程序员一枚。现在原生开发实在是不咋景气,公司现在的项目基本上都是前端的项目,所以现在被调到前端,从小白一枚的角度出发分享一部分项目开发过程中用的比较多的知识吧,今天先学习一个flex布局,这个在项目中用到的实在太多了。
一、介绍
什么叫做弹性布局呢,他就是根据内容多少分配多大的控件,当内容不足时会自动的换行,去适应父布局,这也是他最大的好处 由此他可以去适配多种尺寸的页面。
二、flex结构
咱们先通过网上的一个图片看一下他的具体结构
2025年06月21日
Flex是Flexible Box的缩写,翻译成中文就是“弹性盒子”,用来为盒装模型提供最大的灵活性。任何一个容器都可以指定为Flex布局。
2025年06月21日
摘要: 在某些业务场景下,保护屏幕信息的私密性,防止用户随意截图分享,成为了前端开发者的一个棘手需求。但浏览器和操作系统的设计,真的允许网页开发者完全掌控用户的截图行为吗?本文将深入探讨前端限制截图的技术原理、挑战、尝试方案及其局限性,并提供一些更具可行性的替代策略。
2025年06月21日
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BMI 计算器</title>
<style>
:root {
--body-bg-start: #e8eaf6;
--body-bg-end: #d1c4e9;
--card-bg: rgba(255, 255, 255, 0.9);
--button-gradient-start: #7e57c2;
--button-gradient-end: #9575cd;
--button-hover-gradient-start: #673ab7;
--button-hover-gradient-end: #8e67c7;
--input-border: #bdbdbd;
--input-focus-border: #7e57c2;
--underweight-bg: #b3e5fc;
--normal-bg: #c8e6c9;
--overweight-bg: #ffe0b2;
--obese-bg: #ffcdd2;
--text-color: #212121;
--shadow-color: rgba(0, 0, 0, 0.1);
}
body {
font-family: 'Roboto', sans-serif;
background: linear-gradient(to bottom, var(--body-bg-start), var(--body-bg-end));
color: var(--text-color);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
}
.card {
background-color: var(--card-bg);
border-radius: 20px;
box-shadow: 0 16px 32px var(--shadow-color);
padding: 60px;
width: 90%;
max-width: 700px;
box-sizing: border-box;
}
h1 {
text-align: center;
font-size: 32px;
margin-bottom: 40px;
}
.input-group {
margin-bottom: 30px;
}
label {
display: block;
margin-bottom: 12px;
font-size: 20px;
font-weight: 500;
}
input[type="number"] {
width: 100%;
padding: 18px;
border: 1px solid var(--input-border);
border-radius: 10px;
transition: border-color 0.3s ease;
font-size: 18px;
box-sizing: border-box;
}
input[type="number"]:focus {
border-color: var(--input-focus-border);
outline: none;
}
button {
width: 100%;
padding: 18px;
background: linear-gradient(to right, var(--button-gradient-start), var(--button-gradient-end));
color: white;
border: none;
border-radius: 10px;
box-shadow: 0 8px 16px var(--shadow-color);
cursor: pointer;
transition: background 0.3s ease;
font-size: 20px;
font-weight: 500;
}
button:hover {
background: linear-gradient(to right, var(--button-hover-gradient-start), var(--button-hover-gradient-end));
}
#result {
margin-top: 40px;
padding: 30px;
border-radius: 10px;
text-align: center;
display: none;
font-size: 22px;
}
#result .bmi-value {
font-size: 32px;
font-weight: 700;
}
.danmaku {
position: fixed;
top: 0;
right: 0;
pointer-events: none;
z-index: 999;
white-space: nowrap;
padding: 16px 32px;
border-radius: 30px;
color: white;
background-color: hsl(calc(var(--random-hue, 0) * 360), 30%, 60%);
animation: danmakuMove linear;
}
@keyframes danmakuMove {
from {
transform: translateX(100%);
}
to {
transform: translateX(-100vw);
}
}
</style>
</head>
<body>
<div class="card">
<h1>BMI 计算器</h1>
<div class="input-group">
<label for="height">你的身高(cm)</label>
<input type="number" id="height" placeholder="请输入身高">
</div>
<div class="input-group">
<label for="weight">你的体重(kg)</label>
<input type="number" id="weight" placeholder="请输入体重">
</div>
<button onclick="calculateBMI()">计算 BMI</button>
<div id="result"></div>
</div>
<script>
function calculateBMI() {
const height = parseFloat(document.getElementById('height').value);
const weight = parseFloat(document.getElementById('weight').value);
if (isNaN(height) || isNaN(weight) || height <= 0 || weight <= 0) {
alert('请输入有效的身高和体重值。');
return;
}
const bmi = (weight / ((height / 100) * (height / 100))).toFixed(2);
let category = '';
let message = '';
let resultBg = '';
if (bmi < 18.5) {
category = '偏瘦';
message = '风一吹,你怕是要像风筝一样飘走咯!';
resultBg = getComputedStyle(document.documentElement).getPropertyValue('--underweight-bg');
} else if (bmi >= 18.5 && bmi < 24) {
category = '正常';
message = '嘿,你这身材,老天爷赏饭吃的 “刚刚好” 呀!';
resultBg = getComputedStyle(document.documentElement).getPropertyValue('--normal-bg');
} else if (bmi >= 24 && bmi < 28) {
category = '超重';
message = '再胖点,你能去给熊猫当替身咯!';
resultBg = getComputedStyle(document.documentElement).getPropertyValue('--overweight-bg');
} else {
category = '肥胖';
message = '你不是胖,你是可爱到膨胀啦';
resultBg = getComputedStyle(document.documentElement).getPropertyValue('--obese-bg');
}
const resultDiv = document.getElementById('result');
resultDiv.innerHTML = `你的 BMI 值是:<span class="bmi-value">${bmi}</span>,体重分类:${category}`;
resultDiv.style.display = 'block';
resultDiv.style.backgroundColor = resultBg;
generateDanmaku(message);
}
function generateDanmaku(message) {
const numDanmaku = Math.floor(window.innerHeight / 50);
for (let i = 0; i < numDanmaku; i++) {
const danmaku = document.createElement('div');
danmaku.classList.add('danmaku');
danmaku.style.top = `${i * 50}px`;
danmaku.style.setProperty('--random-hue', Math.random());
danmaku.style.animationDuration = `${Math.random() * 8 + 4}s`;
danmaku.textContent = message;
document.body.appendChild(danmaku);
danmaku.addEventListener('animationend', () => {
danmaku.remove();
});
}
}
</script>
</body>
</html>