You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
3.5 KiB
131 lines
3.5 KiB
/**
|
|
* 高管简历区块交互功能
|
|
*
|
|
* @package Nenghui_Energy_Theme
|
|
*/
|
|
|
|
(function($) {
|
|
'use strict';
|
|
|
|
// 等待DOM加载完成
|
|
$(document).ready(function() {
|
|
initExecutiveProfiles();
|
|
});
|
|
|
|
/**
|
|
* 初始化高管简历功能
|
|
*/
|
|
function initExecutiveProfiles() {
|
|
$('.executive-profiles-block').each(function() {
|
|
const $block = $(this);
|
|
|
|
// 移除加载状态
|
|
$block.removeClass('loading');
|
|
});
|
|
|
|
// 初始化响应式处理
|
|
handleResponsive();
|
|
|
|
// 初始化动画效果
|
|
initAnimations();
|
|
|
|
// 初始化懒加载
|
|
initLazyLoading();
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 响应式处理
|
|
*/
|
|
function handleResponsive() {
|
|
const isMobile = window.innerWidth <= 768;
|
|
|
|
$('.executive-profiles-block').each(function() {
|
|
const $block = $(this);
|
|
|
|
if (isMobile) {
|
|
$block.addClass('mobile-view');
|
|
} else {
|
|
$block.removeClass('mobile-view');
|
|
}
|
|
});
|
|
}
|
|
|
|
// 窗口大小改变时重新处理响应式
|
|
$(window).on('resize', debounce(function() {
|
|
handleResponsive();
|
|
}, 250));
|
|
|
|
/**
|
|
* 防抖函数
|
|
* @param {Function} func 要防抖的函数
|
|
* @param {number} wait 等待时间
|
|
* @param {boolean} immediate 是否立即执行
|
|
*/
|
|
function debounce(func, wait, immediate) {
|
|
let timeout;
|
|
return function executedFunction() {
|
|
const context = this;
|
|
const args = arguments;
|
|
|
|
const later = function() {
|
|
timeout = null;
|
|
if (!immediate) func.apply(context, args);
|
|
};
|
|
|
|
const callNow = immediate && !timeout;
|
|
clearTimeout(timeout);
|
|
timeout = setTimeout(later, wait);
|
|
|
|
if (callNow) func.apply(context, args);
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 懒加载图片(如果有头像图片的话)
|
|
*/
|
|
function initLazyLoading() {
|
|
if ('IntersectionObserver' in window) {
|
|
const imageObserver = new IntersectionObserver((entries, observer) => {
|
|
entries.forEach(entry => {
|
|
if (entry.isIntersecting) {
|
|
const img = entry.target;
|
|
img.src = img.dataset.src;
|
|
img.classList.remove('lazy');
|
|
imageObserver.unobserve(img);
|
|
}
|
|
});
|
|
});
|
|
|
|
document.querySelectorAll('img[data-src]').forEach(img => {
|
|
imageObserver.observe(img);
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 添加动画效果
|
|
*/
|
|
function initAnimations() {
|
|
if ('IntersectionObserver' in window) {
|
|
// 使用 Intersection Observer 来触发动画
|
|
const animationObserver = new IntersectionObserver((entries) => {
|
|
entries.forEach(entry => {
|
|
if (entry.isIntersecting) {
|
|
entry.target.classList.add('animate');
|
|
}
|
|
});
|
|
}, {
|
|
threshold: 0.1,
|
|
rootMargin: '0px 0px -50px 0px'
|
|
});
|
|
|
|
// 观察所有高管卡片
|
|
document.querySelectorAll('.executive-card').forEach(card => {
|
|
animationObserver.observe(card);
|
|
});
|
|
}
|
|
}
|
|
|
|
})(jQuery); |