1.重写汉晶网站

2.修改巨象云数网站“软件开发” 改为 “网站服务”
This commit is contained in:
2025-04-25 11:12:40 +08:00
parent 3eb78af090
commit 6d6f59d7a8
66 changed files with 2101 additions and 129 deletions

View File

@@ -1,5 +1,5 @@
document.addEventListener('DOMContentLoaded', () => {
const elements = document.querySelectorAll('.perCent');
const elements = document.querySelectorAll('.perCent2');
const animatePercentage = (element) => {
// 添加可见类触发CSS过渡效果
@@ -42,4 +42,170 @@ document.addEventListener('DOMContentLoaded', () => {
element.textContent = '1%';
observer.observe(element);
});
});
// ------------------------------
// 获取所需的DOM元素
const container = document.querySelector('.carousel-container');
const list = document.querySelector('.carousel-list');
const items = document.querySelectorAll('.carousel-item');
const prevBtn = document.querySelector('.carousel-arrow-left');
const nextBtn = document.querySelector('.carousel-arrow-right');
const indicators = document.querySelectorAll('.indicator');
// 如果元素不存在,直接返回
if (!container || !list || !items.length) {
console.error('轮播图元素不存在,初始化失败');
return;
}
// 克隆第一个和最后一个项目
const firstClone = items[0].cloneNode(true);
const lastClone = items[items.length - 1].cloneNode(true);
// 将克隆的元素添加到列表中
list.appendChild(firstClone);
list.insertBefore(lastClone, list.firstChild);
// 设置初始位置因为添加了一个项目在前面所以从1开始
let currentIndex = 1;
let interval = null;
let isTransitioning = false;
// 初始化位置
updatePosition(false);
// 更新位置的函数
function updatePosition(withTransition = true) {
// 如果需要过渡动画
if (withTransition) {
list.style.transition = 'transform 0.5s ease';
} else {
list.style.transition = 'none';
}
// 计算位置并应用变换
const position = -currentIndex * 100;
list.style.transform = `translateX(${position}%)`;
// 更新指示器状态注意要减去1因为我们添加了克隆项目
updateIndicators();
}
// 更新指示器状态
function updateIndicators() {
// 考虑循环将currentIndex转换回真实索引
const realIndex = currentIndex - 1;
// 使用模运算确保索引在有效范围内
const activeIndex = (realIndex + items.length) % items.length;
indicators.forEach((indicator, i) => {
indicator.classList.toggle('active', i === activeIndex);
});
}
// 自动播放函数
function startAutoPlay() {
if (interval) clearInterval(interval);
interval = setInterval(nextSlide, 3000);
}
// 暂停自动播放
function stopAutoPlay() {
clearInterval(interval);
}
// 下一张函数
function nextSlide() {
if (isTransitioning) return;
isTransitioning = true;
currentIndex++;
updatePosition();
}
// 上一张函数
function prevSlide() {
if (isTransitioning) return;
isTransitioning = true;
currentIndex--;
updatePosition();
}
// 处理过渡结束事件
list.addEventListener('transitionend', () => {
isTransitioning = false;
// 如果到达了最后一个克隆项
if (currentIndex >= items.length + 1) {
currentIndex = 1;
updatePosition(false);
}
// 如果到达了第一个克隆项
if (currentIndex <= 0) {
currentIndex = items.length;
updatePosition(false);
}
});
// // 绑定按钮事件
// prevBtn.addEventListener('click', () => {
// prevSlide();
// stopAutoPlay();
// startAutoPlay();
// });
// nextBtn.addEventListener('click', () => {
// nextSlide();
// stopAutoPlay();
// startAutoPlay();
// });
// 绑定指示器点击事件
indicators.forEach((indicator, index) => {
indicator.addEventListener('click', () => {
currentIndex = index + 1; // +1因为我们添加了克隆项目
updatePosition();
stopAutoPlay();
startAutoPlay();
});
});
// 鼠标悬停暂停
container.addEventListener('mouseenter', stopAutoPlay);
container.addEventListener('mouseleave', startAutoPlay);
// 添加触摸滑动支持
let touchStartX = 0;
let touchEndX = 0;
container.addEventListener('touchstart', (e) => {
touchStartX = e.touches[0].clientX;
stopAutoPlay();
});
container.addEventListener('touchend', (e) => {
touchEndX = e.changedTouches[0].clientX;
const difference = touchStartX - touchEndX;
if (Math.abs(difference) > 50) {
if (difference > 0) {
nextSlide();
} else {
prevSlide();
}
}
startAutoPlay();
});
// 开始自动播放
startAutoPlay();
});

View File

@@ -0,0 +1,28 @@
document.addEventListener('DOMContentLoaded', function() {
const accordionItems = document.querySelectorAll('.accordion-item');
// 为每个手风琴项添加点击事件
accordionItems.forEach((item, index) => {
const header = item.querySelector('.accordion-header');
header.addEventListener('click', () => {
// 获取当前是否激活
const isActive = item.classList.contains('active');
// 关闭所有项
accordionItems.forEach(item => {
item.classList.remove('active');
});
// 如果点击的不是当前激活项,则展开它
if (!isActive) {
item.classList.add('active');
}
});
// 默认展开第一项
if (index === 0) {
item.classList.add('active');
}
});
});

98
hanJing/js/ourProducts.js Normal file
View File

@@ -0,0 +1,98 @@
document.addEventListener('DOMContentLoaded', function() {
// 获取URL参数中的产品ID
const urlParams = new URLSearchParams(window.location.search);
const productId = urlParams.get('product');
// 显示产品的函数
function showProduct(productId, shouldScroll = false) { // 默认不滚动
console.log('Showing product:', productId);
// 移除所有产品项的active类
const productItems = document.querySelectorAll('.product-item');
productItems.forEach(p => {
p.classList.remove('active');
});
// 找到对应的产品项并添加active类
const targetItem = document.querySelector(`[data-product="${productId}"]`);
if (targetItem) {
targetItem.classList.add('active');
// 确保产品所在的分类是展开的
const category = targetItem.closest('.category-content');
if (category) {
// 先移除所有分类的show类
document.querySelectorAll('.category-content').forEach(c => {
c.classList.remove('show');
});
document.querySelectorAll('.category-header').forEach(h => {
h.classList.remove('active');
});
// 展开当前分类
category.classList.add('show');
const categoryHeader = category.previousElementSibling;
if (categoryHeader) {
categoryHeader.classList.add('active');
}
}
// 隐藏所有详情内容
document.querySelectorAll('.detail-content').forEach(content => {
if (content) {
content.style.display = 'none';
}
});
// 显示目标产品详情
const targetContent = document.getElementById(productId);
if (targetContent) {
targetContent.style.display = 'block';
}
// 只在指定需要滚动时才滚动
if (shouldScroll) {
setTimeout(() => {
targetItem.scrollIntoView({ behavior: 'smooth', block: 'center' });
}, 100);
}
}
}
// 初始化根据URL参数决定行为
if (productId) {
// 如果有产品ID参数则显示对应产品并滚动
showProduct(productId, true); // 有参数时滚动
} else {
// 没有参数时,显示第一个产品但不滚动
const firstProduct = document.querySelector('.product-item');
if (firstProduct) {
showProduct(firstProduct.dataset.product, false); // 无参数时不滚动
}
}
// 产品项点击处理
const productItems = document.querySelectorAll('.product-item');
productItems.forEach(item => {
item.addEventListener('click', function() {
const productId = this.dataset.product;
// 点击产品项时需要滚动
showProduct(productId, true);
updateURL(productId);
});
});
// 更新URL函数
function updateURL(productId) {
const newURL = new URL(window.location.href);
newURL.searchParams.set('product', productId);
window.history.pushState({ productId }, '', newURL);
}
// 处理浏览器后退/前进
window.addEventListener('popstate', function(event) {
if (event.state && event.state.productId) {
showProduct(event.state.productId, true);
}
});
});