difference between "visibility:hidden" and "display:none"

本文介绍了CSS中两种隐藏元素的方法:visibility:hidden与display:none的区别。visibility:hidden使元素不可见但仍保留其空间;而display:none则移除元素所占的空间,如同元素不存在一般。

visibility:hidden hides an element, but it will still take up the same space as before. The element will be hidden, but still affect the layout.

 

display:none hides an element, and it will not take up any space. The element will be hidden, and the page will be displayed as the element is not there:

 

http://www.w3schools.com/css/css_display_visibility.asp

<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>紫华云慧 - 官网(优化版)</title> <style> /* 全局重置 */ * { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } html, body { height: 100%; overflow: hidden; /* 防止默认滚动 */ } /* 页眉样式 */ .header { position: fixed; top: 0; left: 0; width: 100%; height: 70px; background: rgba(0, 0, 0, 0.7); color: white; display: flex; align-items: center; justify-content: space-between; padding: 0 30px; z-index: 25; backdrop-filter: blur(10px); border-bottom: 1px solid rgba(255, 255, 255, 0.1); } .logo { font-size: 1.8rem; font-weight: bold; color: #9370db; } .nav-links { display: flex; gap: 30px; } .nav-links a { color: white; text-decoration: none; font-weight: 500; transition: color 0.3s; } .nav-links a:hover { color: #9370db; } /* 主屏幕区域样式 */ .main-screen { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d); display: flex; flex-direction: column; justify-content: center; align-items: center; color: white; text-align: center; z-index: 10; padding-top: 70px; } .main-title { font-size: 4rem; margin-bottom: 1rem; text-shadow: 2px 2px 10px rgba(0, 0, 0, 0.3); } .main-subtitle { font-size: 1.5rem; margin-bottom: 2rem; } /* 覆盖层样式 */ .cover-container { position: fixed; bottom: 0; left: 0; width: 100%; height: 0; z-index: 15; overflow: hidden; transition: height 0.5s cubic-bezier(0.33, 1, 0.68, 1); /* 优化过渡曲线 */ will-change: height; /* 提示浏览器优化 */ } /* 内容块容器 */ .content-blocks { width: 100%; display: flex; flex-direction: column; } /* 内容块通用样式 */ .content-block { width: 100%; min-height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 80px 10%; color: white; } /* 四个内容块的不同背景色 */ .block-1 { background: linear-gradient(135deg, #1a2a6c, #2c3e50); } .block-2 { background: linear-gradient(135deg, #8a2be2, #6a11cb); } .block-3 { background: linear-gradient(135deg, #b21f1f, #8B0000); } .block-4 { background: linear-gradient(135deg, #0d5c63, #44a08d); } .block-title { font-size: 2.8rem; margin-bottom: 1.5rem; font-weight: 700; text-align: center; } .block-content { font-size: 1.2rem; line-height: 1.8; max-width: 800px; text-align: center; margin-bottom: 2rem; } .features-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 25px; margin-top: 40px; width: 100%; max-width: 1000px; } .feature-card { background: rgba(255, 255, 255, 0.1); padding: 25px; border-radius: 10px; text-align: center; backdrop-filter: blur(10px); border: 1px solid rgba(255, 255, 255, 0.1); transform: translateZ(0); /* 启用GPU加速 */ } .feature-icon { font-size: 2.5rem; margin-bottom: 15px; } .feature-title { font-size: 1.4rem; margin-bottom: 15px; } /* 右侧导航栏样式 */ .side-nav { position: fixed; right: 30px; top: 50%; transform: translateY(-50%); background: rgba(255, 255, 255, 0.1); backdrop-filter: blur(10px); border-radius: 20px; padding: 15px 10px; z-index: 20; opacity: 0; visibility: hidden; transition: opacity 0.5s ease, visibility 0.5s ease; } .side-nav.visible { opacity: 1; visibility: visible; } .side-nav ul { list-style: none; } .side-nav li { margin: 15px 0; text-align: center; } .side-nav a { color: white; text-decoration: none; font-size: 1.2rem; display: block; padding: 10px; border-radius: 15px; transition: background 0.3s; } .side-nav a:hover { background: rgba(255, 255, 255, 0.2); } /* 响应式设计 */ @media (max-width: 768px) { .main-title { font-size: 2.5rem; } .main-subtitle { font-size: 1.2rem; } .block-title { font-size: 2.2rem; } .block-content { font-size: 1.1rem; } .features-grid { grid-template-columns: 1fr; } .nav-links { display: none; } .side-nav { display: none; } } /* 滚动提示 */ .scroll-hint { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); color: white; background: rgba(0, 0, 0, 0.5); padding: 10px 20px; border-radius: 20px; z-index: 20; animation: pulse 2s infinite; display: none; } @keyframes pulse { 0% { opacity: 0.7; } 50% { opacity: 1; } 100% { opacity: 0.7; } } </style> </head> <body> <!-- 页眉 --> <header class="header"> <div class="logo">紫华云慧</div> <nav class="nav-links"> <a href="#block-1">首页</a> <a href="#block-2">服务</a> <a href="#block-3">案例</a> <a href="#block-4">联系</a> </nav> </header> <!-- 主页面 --> <div class="main-screen"> <h1 class="main-title">紫华云慧</h1> <p class="main-subtitle">创新科技,智慧未来</p> </div> <!-- 覆盖层 --> <div class="cover-container" id="coverContainer"> <div class="content-blocks"> <!-- 内容块1 --> <section class="content-block block-1" id="block-1"> <h2 class="block-title">关于我们</h2> <p class="block-content">紫华云慧是一家专注于人工智能和大数据技术的创新企业,致力于为各行业提供智能化解决方案。</p> <div class="features-grid"> <div class="feature-card"> <div class="feature-icon">🚀</div> <h3 class="feature-title">技术创新</h3> <p>专注于前沿技术研发,引领行业创新</p> </div> <div class="feature-card"> <div class="feature-icon">🤝</div> <h3 class="feature-title">客户至上</h3> <p>以客户需求为中心,提供定制化解决方案</p> </div> <div class="feature-card"> <div class="feature-icon">🌐</div> <h3 class="feature-title">全球视野</h3> <p>立足本土,面向全球,拥抱数字化转型</p> </div> </div> </section> <!-- 内容块2 --> <section class="content-block block-2" id="block-2"> <h2 class="block-title">我们的服务</h2> <p class="block-content">我们提供全方位的数字化解决方案,助力企业实现智能化转型。</p> <div class="features-grid"> <div class="feature-card"> <div class="feature-icon">🤖</div> <h3 class="feature-title">AI解决方案</h3> <p>为企业提供定制化人工智能应用</p> </div> <div class="feature-card"> <div class="feature-icon">📊</div> <h3 class="feature-title">数据分析</h3> <p>深度挖掘数据价值,驱动业务增长</p> </div> <div class="feature-card"> <div class="feature-icon">☁️</div> <h3 class="feature-title">云服务</h3> <p>安全可靠的云端部署与管理</p> </div> </div> </section> <!-- 内容块3 --> <section class="content-block block-3" id="block-3"> <h2 class="block-title">成功案例</h2> <p class="block-content">我们已为多家知名企业提供数字化转型服务,取得了显著成果。</p> <div class="features-grid"> <div class="feature-card"> <div class="feature-icon">🏦</div> <h3 class="feature-title">金融行业</h3> <p>为银行提供智能风控和客户服务解决方案</p> </div> <div class="feature-card"> <div class="feature-icon">🏥</div> <h3 class="feature-title">医疗健康</h3> <p>助力医院实现智能化诊断和管理</p> </div> <div class="feature-card"> <div class="feature-icon">🏭</div> <h3 class="feature-title">智能制造</h3> <p>为制造企业提供工业4.0转型方案</p> </div> </div> </section> <!-- 内容块4 --> <section class="content-block block-4" id="block-4"> <h2 class="block-title">联系我们</h2> <p class="block-content">欢迎与我们联系,探讨合作机会。</p> <div class="features-grid"> <div class="feature-card"> <div class="feature-icon">📞</div> <h3 class="feature-title">电话咨询</h3> <p>400-123-4567</p> </div> <div class="feature-card"> <div class="feature-icon">✉️</div> <h3 class="feature-title">邮件联系</h3> <p>info@zihuayunhui.com</p> </div> <div class="feature-card"> <div class="feature-icon">🏢</div> <h3 class="feature-title">公司地址</h3> <p>北京市海淀区科技园区88号</p> </div> </div> </section> </div> </div> <!-- 右侧导航栏 --> <nav class="side-nav" id="sideNav"> <ul> <li><a href="#block-1">关于</a></li> <li><a href="#block-2">服务</a></li> <li><a href="#block-3">案例</a></li> <li><a href="#block-4">联系</a></li> </ul> </nav> <div class="scroll-hint" id="scrollHint">使用鼠标滚轮向下滚动</div> <script> // 性能优化版本 (function() { // 获取DOM元素 const coverContainer = document.getElementById('coverContainer'); const scrollHint = document.getElementById('scrollHint'); const sideNav = document.getElementById('sideNav'); // 缓存窗口高度 const windowHeight = window.innerHeight; let totalContentHeight = 0; // 计算内容总高度 const contentBlocks = document.querySelectorAll('.content-block'); contentBlocks.forEach(block => { totalContentHeight += block.offsetHeight; }); // 初始设置 let coverHeight = 0; let targetHeight = 0; let lastScrollTime = 0; let isAnimating = false; let animationId = null; let scrollDelta = 0; // 显示滚动提示 setTimeout(() => { scrollHint.style.display = 'block'; setTimeout(() => { scrollHint.style.display = 'none'; }, 3000); }, 2000); // 使用requestAnimationFrame进行节流处理滚动事件 let ticking = false; // 监听鼠标滚轮事件 - 使用被动事件提高性能 window.addEventListener('wheel', handleWheel, { passive: false }); // 监听触摸事件(移动设备支持) let touchStartY = 0; window.addEventListener('touchstart', function(e) { touchStartY = e.touches[0].clientY; }, { passive: true }); window.addEventListener('touchmove', function(e) { const touchY = e.touches[0].clientY; const deltaY = touchStartY - touchY; // 累积滚动量 scrollDelta += deltaY * 2; if (!ticking) { requestAnimationFrame(() => { handleScroll(scrollDelta); scrollDelta = 0; ticking = false; }); ticking = true; } touchStartY = touchY; e.preventDefault(); }, { passive: false }); // 处理鼠标滚轮事件 function handleWheel(e) { // 防止默认滚动行为 e.preventDefault(); // 获取滚动方向和距离 const delta = e.deltaY; // 累积滚动量 scrollDelta += delta; // 使用requestAnimationFrame进行节流 if (!ticking) { requestAnimationFrame(() => { handleScroll(scrollDelta); scrollDelta = 0; ticking = false; }); ticking = true; } } // 处理滚动的核心函数 function handleScroll(delta) { // 根据滚动距离调整目标高度 targetHeight += delta * 0.8; // 限制目标高度范围 targetHeight = Math.max(0, Math.min(targetHeight, totalContentHeight)); // 控制右侧导航栏的显示 if (targetHeight > windowHeight * 0.3) { sideNav.classList.add('visible'); } else { sideNav.classList.remove('visible'); } // 如果不在动画中,启动动画 if (!isAnimating) { isAnimating = true; animateCover(); } } // 使用requestAnimationFrame实现平滑动画 function animateCover() { // 计算缓动效果 - 使用更平滑的缓动函数 const easing = 0.15; const difference = targetHeight - coverHeight; // 如果差异很小,直接设置目标值 if (Math.abs(difference) < 1) { coverHeight = targetHeight; coverContainer.style.height = coverHeight + 'px'; isAnimating = false; return; } // 应用缓动效果 coverHeight += difference * easing; // 应用高度变化 coverContainer.style.height = coverHeight + 'px'; // 继续动画 animationId = requestAnimationFrame(animateCover); } // 添加键盘支持 window.addEventListener('keydown', function(e) { if (e.key === 'ArrowDown') { handleScroll(40); e.preventDefault(); } else if (e.key === 'ArrowUp') { handleScroll(-40); e.preventDefault(); } else if (e.key === ' ') { // 空格键跳转到底部或顶部 if (coverHeight < totalContentHeight / 2) { targetHeight = totalContentHeight; } else { targetHeight = 0; } if (!isAnimating) { isAnimating = true; animateCover(); } e.preventDefault(); } }); // 平滑滚动到锚点 document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function(e) { e.preventDefault(); const targetId = this.getAttribute('href'); const targetElement = document.querySelector(targetId); if (targetElement) { // 如果覆盖层未展开,先展开 if (targetHeight < windowHeight * 0.5) { targetHeight = windowHeight; if (!isAnimating) { isAnimating = true; animateCover(); } } // 计算目标位置 const targetPosition = targetElement.offsetTop; // 平滑滚动到目标位置 coverContainer.scrollTo({ top: targetPosition, behavior: 'smooth' }); } }); }); // 初始化 coverContainer.style.height = '0px'; // 监听窗口大小变化 window.addEventListener('resize', function() { // 重新计算内容高度 totalContentHeight = 0; contentBlocks.forEach(block => { totalContentHeight += block.offsetHeight; }); }); })(); </script> </body> </html> 添加详细注释
09-17
内容概要:本文系统阐述了Java Persistence API(JPA)的核心概念、技术架构、核心组件及实践应用,重点介绍了JPA作为Java官方定义的对象关系映射(ORM)规范,如何通过实体类、EntityManager、JPQL和persistence.xml配置文件实现Java对象与数据库表之间的映射与操作。文章详细说明了JPA解决的传统JDBC开发痛点,如代码冗余、对象映射繁琐、跨数据库兼容性差等问题,并解析了JPA与Hibernate、EclipseLink等实现框架的关系。同时提供了基于Hibernate和MySQL的完整实践案例,涵盖Maven依赖配置、实体类定义、CRUD操作实现等关键步骤,并列举了常用JPA注解及其用途。最后总结了JPA的标准化优势、开发效率提升能力及在Spring生态中的延伸应用。 适合人群:具备一定Java基础,熟悉基本数据库操作,工作1-3年的后端开发人员或正在学习ORM技术的中级开发者。 使用场景及目标:①理解JPA作为ORM规范的核心原理与组件协作机制;②掌握基于JPA+Hibernate进行数据库操作的开发流程;③为技术选型、团队培训或向Spring Data JPA过渡提供理论与实践基础。 阅读建议:此资源以理论结合实践的方式讲解JPA,建议读者在学习过程中同步搭建环境,动手实现文中示例代码,重点关注EntityManager的使用、JPQL语法特点以及注解配置规则,从而深入理解JPA的设计思想与工程价值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值