/**
* 2026年江西省教学成果奖申报网站 - 交互脚本
*/
document.addEventListener('DOMContentLoaded', function() {
// 先初始化开场动画
initIntroAnimation();
});
/**
* 开场动画 - 主页火车动画
*/
function initIntroAnimation() {
const heroTrainAnimation = document.getElementById('heroTrainAnimation');
// 页面加载后立即启动动画
if (heroTrainAnimation) {
// 使用 requestAnimationFrame 确保在页面渲染后立即执行
requestAnimationFrame(() => {
heroTrainAnimation.classList.add('animate');
});
}
// 初始化其他功能
initNavigation();
initScrollReveal();
initSmoothScroll();
initCounterAnimation();
initBackToTop();
initMaterialsFilter();
initTabs();
initIntroTabs();
initCharts();
initPDFViewer();
}
/**
* 导航栏交互
*/
function initNavigation() {
const nav = document.getElementById('mainNav');
const navLinks = document.querySelectorAll('.nav-link');
const sections = document.querySelectorAll('section[id]');
// 滚动时更新导航栏样式
window.addEventListener('scroll', () => {
if (window.scrollY > 100) {
nav.classList.add('scrolled');
} else {
nav.classList.remove('scrolled');
}
// 更新当前活动链接
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop - 150;
if (window.scrollY >= sectionTop) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === '#' + current) {
link.classList.add('active');
}
});
});
// 移动端菜单切换
const navToggle = document.getElementById('navToggle');
const navMenu = document.querySelector('.nav-menu');
if (navToggle) {
navToggle.addEventListener('click', () => {
navMenu.classList.toggle('active');
navToggle.classList.toggle('active');
});
}
}
/**
* 滚动显示动画
*/
function initScrollReveal() {
const revealElements = document.querySelectorAll('.section-header, .result-card, .innovation-card, .material-card');
const revealObserver = new IntersectionObserver((entries) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
// 添加延迟,使动画更流畅
setTimeout(() => {
entry.target.classList.add('revealed');
}, index * 100);
revealObserver.unobserve(entry.target);
}
});
}, {
threshold: 0.05,
rootMargin: '0px 0px -30px 0px'
});
revealElements.forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(20px)';
el.style.transition = 'opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1), transform 0.5s cubic-bezier(0.4, 0, 0.2, 1)';
revealObserver.observe(el);
});
}
// 添加revealed类样式
document.head.insertAdjacentHTML('beforeend', `
`);
/**
* 平滑滚动
*/
function initSmoothScroll() {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const offsetTop = target.offsetTop - 80;
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
// 关闭移动端菜单
const navMenu = document.querySelector('.nav-menu');
const navToggle = document.getElementById('navToggle');
if (navMenu && navMenu.classList.contains('active')) {
navMenu.classList.remove('active');
navToggle.classList.remove('active');
}
}
});
});
}
/**
* 数字滚动动画
*/
function initCounterAnimation() {
const counters = document.querySelectorAll('.stat-number[data-count]');
const counterObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const counter = entry.target;
const target = parseInt(counter.getAttribute('data-count'));
const duration = 2000;
const step = target / (duration / 16);
let current = 0;
const updateCounter = () => {
current += step;
if (current < target) {
counter.textContent = Math.floor(current);
requestAnimationFrame(updateCounter);
} else {
counter.textContent = target;
}
};
updateCounter();
counterObserver.unobserve(counter);
}
});
}, { threshold: 0.5 });
counters.forEach(counter => counterObserver.observe(counter));
}
/**
* 返回顶部
*/
function initBackToTop() {
const backToTop = document.getElementById('backToTop');
if (backToTop) {
window.addEventListener('scroll', () => {
if (window.scrollY > 500) {
backToTop.classList.add('visible');
} else {
backToTop.classList.remove('visible');
}
});
backToTop.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
}
}
/**
* 材料筛选
*/
function initMaterialsFilter() {
const filterBtns = document.querySelectorAll('.filter-btn');
const materialCards = document.querySelectorAll('.material-card');
filterBtns.forEach(btn => {
btn.addEventListener('click', () => {
// 更新按钮状态
filterBtns.forEach(b => b.classList.remove('active'));
btn.classList.add('active');
// 筛选材料
const filter = btn.getAttribute('data-filter');
materialCards.forEach(card => {
if (filter === 'all' || card.getAttribute('data-category') === filter) {
card.style.display = 'block';
card.style.animation = 'fadeIn 0.4s ease';
} else {
card.style.display = 'none';
}
});
});
});
}
/**
* 初始化选项卡 - 鼠标悬停显示内容
*/
function initTabs() {
const tabBtns = document.querySelectorAll('.tab-btn');
const tabContents = document.querySelectorAll('.tab-content');
tabBtns.forEach(btn => {
// 鼠标悬停时显示内容
btn.addEventListener('mouseenter', () => {
// 移除所有active类
tabBtns.forEach(b => b.classList.remove('active'));
tabContents.forEach(c => c.classList.remove('active'));
// 添加active类到当前按钮
btn.classList.add('active');
// 显示对应内容
const tabId = btn.getAttribute('data-tab');
const targetContent = document.getElementById(tabId);
if (targetContent) {
targetContent.classList.add('active');
}
});
});
}
/**
* 初始化简介选项卡 - 鼠标悬停显示内容
*/
function initIntroTabs() {
const tabBtns = document.querySelectorAll('.intro-tab');
const tabContents = document.querySelectorAll('.intro-content');
tabBtns.forEach(btn => {
// 鼠标悬停时显示内容
btn.addEventListener('mouseenter', () => {
// 移除所有active类
tabBtns.forEach(b => b.classList.remove('active'));
tabContents.forEach(c => c.classList.remove('active'));
// 添加active类到当前按钮
btn.classList.add('active');
// 显示对应内容
const tabId = btn.getAttribute('data-tab');
const targetContent = document.getElementById(tabId);
if (targetContent) {
targetContent.classList.add('active');
}
});
});
}
/**
* 初始化图表
*/
function initCharts() {
// 简单的CSS动画图表
const chartBars = document.querySelectorAll('.chart-bar');
const chartObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const bar = entry.target;
const width = bar.getAttribute('data-width');
bar.style.width = width + '%';
chartObserver.unobserve(bar);
}
});
}, { threshold: 0.5 });
chartBars.forEach(bar => chartObserver.observe(bar));
}
/**
* 初始化PDF查看器
*/
function initPDFViewer() {
const pdfBtns = document.querySelectorAll('.pdf-btn');
const pdfFrame = document.getElementById('pdfFrame');
const pdfTitle = document.getElementById('pdfTitle');
const pdfPlaceholder = document.getElementById('pdfPlaceholder');
const pdfClose = document.getElementById('pdfClose');
// 默认加载目录PDF
if (pdfFrame && pdfTitle) {
pdfFrame.src = 'images/himages/zhichengcailiao-mulu.pdf';
pdfTitle.textContent = '支撑材料(目录)';
pdfPlaceholder.style.display = 'none';
pdfFrame.classList.add('active');
}
// 点击PDF按钮
pdfBtns.forEach(btn => {
btn.addEventListener('click', () => {
// 移除所有按钮的active状态
pdfBtns.forEach(b => b.classList.remove('active'));
// 添加当前按钮的active状态
btn.classList.add('active');
// 获取PDF文件名和标题
const pdfFile = btn.getAttribute('data-pdf');
const pdfBtnTitle = btn.querySelector('.pdf-title').textContent;
// 更新标题
pdfTitle.textContent = pdfBtnTitle + ' - 支撑材料';
// 隐藏占位符,显示iframe
pdfPlaceholder.style.display = 'none';
pdfFrame.classList.add('active');
// 设置PDF路径
pdfFrame.src = pdfFile;
});
});
// 点击关闭按钮 - 返回目录视图
if (pdfClose) {
pdfClose.addEventListener('click', () => {
// 移除所有按钮的active状态
pdfBtns.forEach(b => b.classList.remove('active'));
// 重置标题为目录
pdfTitle.textContent = '支撑材料(目录)';
// 隐藏占位符,显示iframe并加载目录PDF
pdfPlaceholder.style.display = 'none';
pdfFrame.classList.add('active');
pdfFrame.src = '支撑材料(目录).pdf';
});
}
}
// 添加淡入动画样式
document.head.insertAdjacentHTML('beforeend', `
`);