70 lines
2.2 KiB
JavaScript
70 lines
2.2 KiB
JavaScript
// Smooth scrolling for anchor links
|
|
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
|
anchor.addEventListener('click', function (e) {
|
|
e.preventDefault();
|
|
|
|
document.querySelector(this.getAttribute('href')).scrollIntoView({
|
|
behavior: 'smooth'
|
|
});
|
|
});
|
|
});
|
|
|
|
// Three.js 3D Visual
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
const container = document.getElementById('3d-canvas-container');
|
|
if (container) {
|
|
let scene, camera, renderer, cube;
|
|
|
|
function init() {
|
|
// Scene
|
|
scene = new THREE.Scene();
|
|
|
|
// Camera
|
|
camera = new THREE.PerspectiveCamera(75, container.clientWidth / container.clientHeight, 0.1, 1000);
|
|
camera.position.z = 5;
|
|
|
|
// Renderer
|
|
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
|
|
renderer.setSize(container.clientWidth, container.clientHeight);
|
|
container.appendChild(renderer.domElement);
|
|
|
|
// Cube
|
|
const geometry = new THREE.BoxGeometry(2, 2, 2);
|
|
const material = new THREE.MeshStandardMaterial({ color: 0x8B5CF6, roughness: 0.5, metalness: 0.5 });
|
|
cube = new THREE.Mesh(geometry, material);
|
|
scene.add(cube);
|
|
|
|
// Lights
|
|
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
|
|
scene.add(ambientLight);
|
|
|
|
const pointLight = new THREE.PointLight(0xffffff, 0.8);
|
|
pointLight.position.set(5, 5, 5);
|
|
scene.add(pointLight);
|
|
|
|
// Animation
|
|
animate();
|
|
}
|
|
|
|
function animate() {
|
|
requestAnimationFrame(animate);
|
|
|
|
cube.rotation.x += 0.005;
|
|
cube.rotation.y += 0.005;
|
|
|
|
renderer.render(scene, camera);
|
|
}
|
|
|
|
function onWindowResize() {
|
|
if (container.clientWidth > 0 && container.clientHeight > 0) {
|
|
camera.aspect = container.clientWidth / container.clientHeight;
|
|
camera.updateProjectionMatrix();
|
|
renderer.setSize(container.clientWidth, container.clientHeight);
|
|
}
|
|
}
|
|
|
|
window.addEventListener('resize', onWindowResize, false);
|
|
|
|
init();
|
|
}
|
|
}); |