init: TEALab 2025 实验室网站项目
从百度网盘 /apps/bypy/dofile/ 下载的完整项目结构,包含: - dofile/: Flask 后端(端口 5000)+ 静态前端(端口 6002) - officefile/: 项目相关文档 - .gitignore: Python venv / 日志 / 缓存 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,156 @@
|
||||
// Common JavaScript Functions for DAEL Lab Website
|
||||
|
||||
// Initialize Lucide Icons
|
||||
function initIcons() {
|
||||
if (window.lucide) {
|
||||
lucide.createIcons();
|
||||
} else {
|
||||
console.warn("Lucide icons failed to load.");
|
||||
}
|
||||
}
|
||||
|
||||
// Mobile Menu Toggle
|
||||
function initMobileMenu() {
|
||||
const menuBtn = document.getElementById('mobile-menu-btn');
|
||||
const mobileMenu = document.getElementById('mobile-menu');
|
||||
|
||||
if (menuBtn && mobileMenu) {
|
||||
menuBtn.addEventListener('click', () => {
|
||||
mobileMenu.classList.toggle('hidden');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Navbar scroll effect
|
||||
function initNavbarScroll() {
|
||||
window.addEventListener('scroll', () => {
|
||||
const nav = document.getElementById('navbar');
|
||||
if (nav) {
|
||||
if (window.scrollY > 50) {
|
||||
nav.classList.add('shadow-sm');
|
||||
if (nav.classList.contains('h-20')) {
|
||||
nav.classList.replace('h-20', 'h-16');
|
||||
}
|
||||
} else {
|
||||
nav.classList.remove('shadow-sm');
|
||||
if (nav.classList.contains('h-16')) {
|
||||
nav.classList.replace('h-16', 'h-20');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Canvas Animation: Organic Connection Nodes
|
||||
function initCanvasAnimation() {
|
||||
const canvas = document.getElementById('heroCanvas');
|
||||
if (!canvas) return;
|
||||
|
||||
const ctx = canvas.getContext('2d');
|
||||
let width, height;
|
||||
let particles = [];
|
||||
|
||||
function resize() {
|
||||
width = window.innerWidth;
|
||||
height = window.innerHeight;
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
}
|
||||
|
||||
class Particle {
|
||||
constructor() {
|
||||
this.x = Math.random() * width;
|
||||
this.y = Math.random() * height;
|
||||
this.vx = (Math.random() - 0.5) * 0.5;
|
||||
this.vy = (Math.random() - 0.5) * 0.5;
|
||||
this.size = Math.random() * 2 + 1;
|
||||
}
|
||||
|
||||
update() {
|
||||
this.x += this.vx;
|
||||
this.y += this.vy;
|
||||
|
||||
if (this.x < 0 || this.x > width) this.vx *= -1;
|
||||
if (this.y < 0 || this.y > height) this.vy *= -1;
|
||||
}
|
||||
|
||||
draw() {
|
||||
ctx.beginPath();
|
||||
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
|
||||
function initParticles() {
|
||||
particles = [];
|
||||
const particleCount = Math.min(window.innerWidth / 10, 100);
|
||||
for (let i = 0; i < particleCount; i++) {
|
||||
particles.push(new Particle());
|
||||
}
|
||||
}
|
||||
|
||||
function animate() {
|
||||
ctx.clearRect(0, 0, width, height);
|
||||
|
||||
for (let i = 0; i < particles.length; i++) {
|
||||
particles[i].update();
|
||||
particles[i].draw();
|
||||
|
||||
for (let j = i + 1; j < particles.length; j++) {
|
||||
const dx = particles[i].x - particles[j].x;
|
||||
const dy = particles[i].y - particles[j].y;
|
||||
const dist = Math.sqrt(dx * dx + dy * dy);
|
||||
|
||||
if (dist < 150) {
|
||||
ctx.beginPath();
|
||||
ctx.strokeStyle = `rgba(0, 0, 0, ${0.05 - dist/3000})`;
|
||||
ctx.lineWidth = 0.5;
|
||||
ctx.moveTo(particles[i].x, particles[i].y);
|
||||
ctx.lineTo(particles[j].x, particles[j].y);
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
}
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
window.addEventListener('resize', () => {
|
||||
resize();
|
||||
initParticles();
|
||||
});
|
||||
|
||||
resize();
|
||||
initParticles();
|
||||
animate();
|
||||
}
|
||||
|
||||
// Visit Counter
|
||||
function initVisitCounter() {
|
||||
const counterElement = document.getElementById('visit-counter');
|
||||
if (!counterElement) return;
|
||||
|
||||
let count = parseInt(localStorage.getItem('dael_visit_count') || '0');
|
||||
count++;
|
||||
localStorage.setItem('dael_visit_count', count.toString());
|
||||
counterElement.textContent = count.toLocaleString();
|
||||
}
|
||||
|
||||
// Initialize all common functions
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
initIcons();
|
||||
initMobileMenu();
|
||||
initNavbarScroll();
|
||||
initCanvasAnimation();
|
||||
initVisitCounter();
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user