1、什么是弹性布局
Flex是Flexible Box的缩写,翻译成中文就是“弹性盒子”,用来为盒装模型提供最大的灵活性。任何一个容器都可以指定为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>
2025年06月21日
你有没有在阅读开源框架代码时,看到类似Class.forName、Method.invoke这样的代码,却一头雾水,完全不明白它们是在做什么?作为互联网大厂的后端开发人员,在 Java 开发的过程中,相信很多人都曾被 Java 的反射机制难住,明明代码能运行,却不清楚背后到底是怎样实现的 。今天,咱们就一起深入探讨 Java 中的反射原理,解开它的神秘面纱!
2025年06月21日
这篇来说说反射中剩下的两个知识点的其中之一,分别是 Field (属性,领域,字段)和 Method (方法或函数)。
2025年06月21日
使用show()和hide()方法
在普通的javascript编程中,要实现元素的显示、隐藏通常是利用其CSS的display属性或者visibility属性。
在jQuery中提供了show()和hide()两个方法,来直接实现元素对象的显示和隐藏。
jQuery代码:
2025年06月21日
Java反射机制,这个听起来有点神秘的名字,实际上就像是Java世界的“透视镜”,它允许程序在运行时检查和操作类、方法、字段等内容。这种能力让Java变得异常灵活,但也可能带来一些潜在的风险。让我们一起揭开它的神秘面纱吧!
2025年06月21日
兴趣爱好,加上一些工作需要,学习一下Java的Swing桌面应用程序的开发。
学习过程笔记一下。
1、构建一个入门的桌面小程序并运行
参考豆包给的源码:
package com.zx.swing.tool;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class SwingToolMain {
private JFrame frame;
private JTextField textField;
private JTextArea textArea;
public SwingToolMain() {
initialize();
}
private void initialize() {
// 创建主窗口
frame = new JFrame("Java桌面应用示例");
frame.setSize(600, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new BorderLayout(0, 0));
// 创建顶部面板
JPanel topPanel = new JPanel();
frame.getContentPane().add(topPanel, BorderLayout.NORTH);
// 添加标签
JLabel label = new JLabel("输入文本:");
topPanel.add(label);
// 添加文本框
textField = new JTextField();
topPanel.add(textField);
textField.setColumns(30);
// 添加按钮
JButton button = new JButton("添加到列表");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String text = textField.getText();
if (!text.isEmpty()) {
textArea.append(text + "\n");
textField.setText("");
}
}
});
topPanel.add(button);
// 创建中间文本区域
textArea = new JTextArea();
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea);
frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
// 创建底部状态栏
JLabel statusLabel = new JLabel("就绪");
frame.getContentPane().add(statusLabel, BorderLayout.SOUTH);
}
// java com.zx.swing.tool.SwingToolMain
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
try {
SwingToolMain window = new SwingToolMain();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
});
}
}