2016/2/19 position: fixed absolute relative z-index float 半透明效果

本文详细介绍了CSS中position属性的使用方法,包括fixed、absolute和relative定位的区别,并讲解了z-index属性的作用及如何实现元素的层级覆盖。此外,还探讨了float属性以及overflow属性的应用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、positionfixed

  锁定位置(相对于浏览器的位置),例如有些网站的右下角的弹出窗口。

     显示效果  无论滚动条怎么移动  都固定在显示页面的一个位置不动

 

 

二、positionabsolute

  1.外层没有position:absolute(或relative);那么div相对于浏览器定位,如下图中b(距离浏览器右边框为50像素,距离下边框为20像素)。

  2.外层有position:absolute(或relative);那么div相对于外层边框定位,如下图中bb(距离d的右边框50像素,距离d的下边框为20像素)。

示例:

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>无标题文档</title>
 6 <style type="text/css">
 7 .b{
 8     border:5px solid blue;
 9     background-color:#009;
10     width:100px;
11     height:100px;
12     margin:30px;
13     right:50px;
14     bottom:20px;
15     position:absolute;
16     }
17 .c{
18     width:400px;
19     height:200px;
20     border:2px solid red;
21     
22     }
23 .d{
24     border:2px solid red;
25     width:400px;
26     height:200px;
27     position:absolute;
28     }
29 </style>
30 </head>
31 
32 <body>
33 <div class="c"><div class="b">b</div></div>
34 <div class="d"><div class="b">bb</div></div>
35 </body>
36 </html>
不同比例的显示效果图,见下面。

 

 

 

 

三、positionrelative

  相对位置。

  如下图,相对于把此div包含住的div的某个位置进行固定。如果外层没有包含他的,那就相对于浏览器进行相对位置的固定。

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>absolute</title>
 6 <style type="text/css">
 7 #a{
 8     border:5px solid blue;
 9     background-color:#0F3;
10     width:100px;
11     height:100px;
12     margin:10px;
13     position:fixed;
14 
15     }
16 #aa{
17     border:5px solid blue;
18     background-color:#0F3;
19     width:100px;
20     height:100px;
21     margin:10px;
22     left:20px;
23     top:50px;
24     position:relative;
25     }
26 
27 </style>
28 </head>
29 
30 <body>
31 <div id="a">a</div>
32 <div id="aa">aa</div>
33 </body>
34 </html>

显示效果

四、分层(z-index

  z轴方向分层,可以理解为分成一摞纸,层数越高越靠上。

  在上面relative的示例中,我们看到了aa遮住了a,这是因为后写代码的显示级别越靠前,那么在不改变代码顺序的情况下如何让a盖住aa?如下:

示例:

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>无标题文档</title>
 6 <style type="text/css">
 7 .a{
 8     border:5px solid blue;
 9     width:100px;
10     height:100px;
11     background-color:#0F3;
12     margin:10px;
13     position:fixed;
14     z-index:2;/*"2"这个参数可做修改,默认情况下,都是第一层*/
15     }
16 .aa{
17     border:5px solid blue;
18     width:100px;
19     height:100px;
20     margin:10px;
21     background-color:#0F3;
22     left:20px;
23     top:50px;
24     position:relative;
25     }    
26 </style>
27 </head>
28 
29 <body>
30 
31 
32 <div class="a">a</div>
33 <div class="aa">aa</div>
34 </body>
35 </html>

五、floatleftright

Leftright时不用给他规定位置(lefttop),直接相对于浏览器。若外部被包裹,相对于外部div的除去一行的位置的左上或右上显示。

  overflow:hidden;    //超出部分隐藏;scroll,显示出滚动条;

  <div style="clear:both"></div>   //截断流

附:cursor:pointer    鼠标指到上面时的形状

     &copy                  版权符号©

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>无标题文档</title>
 6 <style type="text/css">
 7 #a{
 8     background-color:#0F0;
 9     border:1px solid blue;
10     margin:10px;
11     height:100px;
12     width:100px;
13     float:right;
14     overflow:hidden;/把hidden改为scroll,由隐藏溢出的文字方式,变为有滚动条显示的方式
15     }
16 
17 
18 </style>
19 </head>
20 
21 <body>
22 <div id="a">道可道非常道,名可名非常。无名,天地之始。有名,万物之母。常无欲观其妙,常有欲观其徼。此两者同出而异名。同谓之玄,玄而又玄,众妙之门。</div>
23 </body>
24 </html>

overflow:hidden;形式把溢出的隐藏        overflow:scroll;形式  带滚动条

 

 

半透明效果:

  <div class="box">透明区域<div>

在样式表中的代码为:

.box

{

opacity:0.5; -moz-opacity:0.5 ; filter:alpha(opacity=50)

}

 filter填充   alpha透明   opacity模糊

 

转载于:https://www.cnblogs.com/haodayikeshu/p/5202541.html

<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>关爱展厅</title> <script src="https://cdn.tailwindcss.com"></script> <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet"> <style> body { background: #0f172a; min-height: 100vh; display: flex; justify-content: center; align-items: center; font-family: 'Inter', sans-serif; overflow: hidden; } .gallery-container { perspective: 1000px; width: 100%; height: 100vh; display: flex; justify-content: center; align-items: center; } .carousel { position: relative; width: 300px; height: 400px; transform-style: preserve-3d; /* 使用更平滑的过渡函数 */ transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1); } .carousel-item { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; border-radius: 12px; overflow: hidden; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3); /* 使用will-change优化性能 */ will-change: transform, box-shadow; transition: transform 0.5s cubic-bezier(0.23, 1, 0.32, 1), box-shadow 0.5s cubic-bezier(0.23, 1, 0.32, 1); cursor: pointer; z-index: 5; } .carousel-item:hover { box-shadow: 0 15px 40px rgba(0, 0, 0, 0.5); transform: translateZ(calc(400px + 10px)); /* 悬停时向前移动 */ z-index: 20; /* 确保悬停项在最上层 */ } .carousel-item:active { transform: translateZ(calc(400px)) scale(0.98); transition-duration: 0.2s; } .carousel-item img { width: 100%; height: 100%; object-fit: cover; /* 使用will-change优化性能 */ will-change: transform; transition: transform 0.7s cubic-bezier(0.23, 1, 0.32, 1); } .carousel-item:hover img { transform: scale(1.05); } .carousel-info { position: absolute; bottom: 0; left: 0; right: 0; padding: 20px; background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0) 100%); transform: translateY(20px); opacity: 0; /* 使用will-change优化性能 */ will-change: transform, opacity; transition: transform 0.4s cubic-bezier(0.23, 1, 0.32, 1), opacity 0.4s cubic-bezier(0.23, 1, 0.32, 1); z-index: 30; /* 提高信息卡片的z-index */ } .carousel-item:hover .carousel-info { transform: translateY(0); opacity: 1; } .carousel-title { font-size: 1.5rem; font-weight: bold; margin-bottom: 5px; color: white; } .carousel-desc { font-size: 0.9rem; color: rgba(255, 255, 255, 0.8); } .controls { position: fixed; bottom: 50px; left: 50%; transform: translateX(-50%); display: flex; gap: 20px; z-index: 20; } .control-btn { background: rgba(255, 255, 255, 0.1); color: white; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; /* 使用will-change优化性能 */ will-change: background; transition: background 0.3s ease; } .control-btn:hover { background: rgba(255, 255, 255, 0.2); } #activityBtn { position: fixed; top: 20px; right: 20px; background: rgba(255, 255, 255, 0.1); color: white; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; /* 使用will-change优化性能 */ will-change: background; transition: background 0.3s ease; z-index: 20; } #activityBtn:hover { background: rgba(255, 255, 255, 0.2); } #activityModal { display: none; position: fixed; z-index: 100; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0, 0, 0, 0.7); /* 使用will-change优化性能 */ will-change: opacity; transition: opacity 0.4s cubic-bezier(0.23, 1, 0.32, 1); } .modal-content { background-color: #1e293b; margin: 10% auto; padding: 20px; border-radius: 10px; width: 80%; max-width: 600px; color: white; box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3); /* 使用will-change优化性能 */ will-change: transform, opacity; transform: translateY(20px); opacity: 0; transition: transform 0.5s cubic-bezier(0.23, 1, 0.32, 1), opacity 0.5s cubic-bezier(0.23, 1, 0.32, 1); } .modal-open .modal-content { transform: translateY(0); opacity: 1; } .close { color: #aaa; float: right; font-size: 28px; font-weight: bold; /* 使用will-change优化性能 */ will-change: color; transition: color 0.3s ease; } .close:hover, .close:focus { color: white; text-decoration: none; cursor: pointer; } .activity-list { margin-top: 20px; } .activity-item { padding: 15px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.1); /* 使用will-change优化性能 */ will-change: background; transition: background 0.2s ease; } .activity-item:hover { background: rgba(255, 255, 255, 0.03); } .activity-item:last-child { border-bottom: none; } .activity-date { font-weight: bold; color: #94a3b8; } @media (max-width: 600px) { .carousel { width: 250px; height: 350px; } .modal-content { width: 90%; margin: 5% auto; } #activityBtn { top: 10px; right: 10px; padding: 8px 15px; font-size: 0.9rem; } } </style> </head> <body> <div class="gallery-container"> <div id="carousel" class="carousel"> <!-- 图片将通过JS动态添加 --> </div> </div> <div class="controls"> <button id="prevBtn" class="control-btn"> <i class="fa fa-arrow-left mr-2"></i>上一张 </button> <button id="nextBtn" class="control-btn"> 下一张<i class="fa fa-arrow-right ml-2"></i> </button> </div> <button id="activityBtn" class="control-btn"> <i class="fa fa-calendar mr-2"></i>活动清单 </button> <div id="activityModal" class="modal"> <div class="modal-content"> <span class="close">×</span> <h2 class="text-xl font-bold mb-4">7月活动清单</h2> <div class="activity-list"> <!-- 活动列表将通过JS动态生成 --> </div> </div> </div> <script> document.addEventListener('DOMContentLoaded', () => { const carousel = document.getElementById('carousel'); const prevBtn = document.getElementById('prevBtn'); const nextBtn = document.getElementById('nextBtn'); const activityBtn = document.getElementById('activityBtn'); const activityModal = document.getElementById('activityModal'); const closeBtn = document.querySelector('.close'); const itemsCount = 5; // 更新为5个项目 const radius = 400; let currentAngle = 0; const angleStep = 360 / itemsCount; // 重新计算角度步长 // 优化后的主题数据,添加了"新员工融入"和"任务分派" const communicationRecords = [ { id: 1001, title: "员工生病探望", participants: ["人力资源部: 王经理", "部门主管: 张主管"], content: "前往医院探望生病住院的员工,带去公司关怀和慰问品,了解康复情况并协调工作安排。", time: "2023-06-15", location: "市中心医院", followUp: "人力资源部持续跟进员工康复进度,部门安排同事临时接手相关工作。", topic: "生病看望", imageId: 1005 // 医疗相关图片 }, { id: 1003, title: "6月员工生日会", participants: ["行政部: 刘主管", "6月寿星: 全体成员"], content: "举办6月员工生日会,庆祝员工生日,分享蛋糕和礼物,增强团队凝聚力。", time: "2023-06-25", location: "公司会议室", followUp: "行政部收集员工反馈,持续优化生日关怀活动形式。", topic: "生日关怀", imageId: 1003 // 庆祝相关图片 }, { id: 1004, title: "端午节福利发放", participants: ["行政部: 全体成员", "各部门代表"], content: "为全体员工发放端午节福利,包括粽子、咸鸭蛋等传统节日礼品,表达节日问候。", time: "2023-06-22", location: "公司大厅", followUp: "行政部持续关注员工福利需求,准备其他节日福利方案。", topic: "节日福利", imageId: 1004 // 食物相关图片 }, { id: 1005, title: "新员工入职欢迎会", participants: ["人力资源部: 李主管", "新员工: 张明、王芳", "部门同事代表"], content: "为新员工举办入职欢迎会,介绍公司文化、规章制度,帮助新员工快速融入团队。", time: "2023-06-30", location: "公司培训室", followUp: "各部门安排导师指导新员工,定期跟进新员工适应情况。", topic: "新员工融入", imageId: 1006 // 团队合作相关图片 }, { id: 1006, title: "项目任务分派会议", participants: ["项目经理: 赵经理", "开发团队: 全体成员", "测试团队: 负责人"], content: "召开项目任务分派会议,明确各成员职责和任务,制定项目计划和时间节点。", time: "2023-07-05", location: "公司会议室B", followUp: "定期召开项目进度会议,及时解决遇到的问题,确保项目顺利进行。", topic: "任务分派", imageId: 1008 // 商务会议相关图片 } ]; // 更新活动列表,添加新员工融入和任务分派相关活动 const currentMonthActivities = [ { date: "2023-07-05", title: "新一期员工入职培训", type: "培训", location: "公司培训室", participants: "人力资源部、新入职员工" }, { date: "2023-07-10", title: "员工户外拓展训练", type: "团队活动", location: "城市郊外拓展基地", participants: "全体员工" }, { date: "2023-07-15", title: "客户满意度调研分析", type: "分析会", location: "公司会议室A", participants: "市场部、客服部" }, { date: "2023-07-20", title: "第三季度项目任务分派", type: "任务分配", location: "公司大会议室", participants: "各部门负责人、项目团队" }, { date: "2023-07-25", title: "产品创新头脑风暴", type: "研讨会", location: "公司创意空间", participants: "产品部、研发部、设计部" } ]; function createCarouselItems() { for (let i = 0; i < itemsCount; i++) { const angle = (i * angleStep) * (Math.PI / 180); const item = document.createElement('div'); item.className = 'carousel-item'; item.style.transform = `rotateY(${i * angleStep}deg) translateZ(${radius}px)`; item.dataset.index = i; item.dataset.topic = communicationRecords[i].topic; const img = document.createElement('img'); img.src = `https://picsum.photos/id/${communicationRecords[i].imageId}/600/800`; img.alt = communicationRecords[i].title; const info = document.createElement('div'); info.className = 'carousel-info'; const title = document.createElement('h3'); title.className = 'carousel-title'; title.textContent = communicationRecords[i].title; const desc = document.createElement('p'); desc.className = 'carousel-desc'; desc.textContent = communicationRecords[i].participants.join('、'); info.appendChild(title); info.appendChild(desc); item.appendChild(img); item.appendChild(info); carousel.appendChild(item); item.addEventListener('click', () => { const topic = encodeURIComponent(communicationRecords[i].topic); console.log(`跳转到主题: ${topic}`); item.style.transform = `rotateY(${i * angleStep}deg) translateZ(${radius - 10}px) scale(0.98)`; setTimeout(() => { item.style.transform = `rotateY(${i * angleStep}deg) translateZ(${radius}px)`; // 注意:这里使用了相对路径,实际使用时请根据你的项目结构调整 window.location.href = `./photo-wall.html?topic=${topic}`; }, 150); }); } } function createActivityList() { const activityList = document.querySelector('.activity-list'); activityList.innerHTML = ''; currentMonthActivities.forEach(activity => { const activityItem = document.createElement('div'); activityItem.className = 'activity-item'; const dateElement = document.createElement('div'); dateElement.className = 'activity-date'; dateElement.textContent = activity.date; const titleElement = document.createElement('h3'); titleElement.className = 'text-lg font-semibold mt-1'; titleElement.textContent = activity.title; const typeElement = document.createElement('div'); typeElement.className = 'text-sm text-blue-400 mt-1'; typeElement.textContent = activity.type; const locationElement = document.createElement('div'); locationElement.className = 'text-sm text-gray-300 mt-1'; locationElement.innerHTML = `<i class="fa fa-map-marker mr-1"></i> ${activity.location}`; const participantsElement = document.createElement('div'); participantsElement.className = 'text-sm text-gray-300 mt-1'; participantsElement.innerHTML = `<i class="fa fa-users mr-1"></i> ${activity.participants}`; activityItem.appendChild(dateElement); activityItem.appendChild(titleElement); activityItem.appendChild(typeElement); activityItem.appendChild(locationElement); activityItem.appendChild(participantsElement); activityList.appendChild(activityItem); }); } function rotateCarousel(angle) { // 使用requestAnimationFrame优化动画性能 requestAnimationFrame(() => { carousel.style.transform = `rotateY(${angle}deg)`; }); } prevBtn.addEventListener('click', () => { currentAngle += angleStep; rotateCarousel(currentAngle); }); nextBtn.addEventListener('click', () => { currentAngle -= angleStep; rotateCarousel(currentAngle); }); let isDragging = false; let startX, startRotation; let lastAnimationFrameId = null; document.addEventListener('mousedown', (e) => { if (!e.target.closest('.carousel-item')) { isDragging = true; startX = e.clientX; startRotation = currentAngle; document.body.style.cursor = 'grabbing'; // 防止拖动时选择文本 document.body.style.userSelect = 'none'; } }); document.addEventListener('mousemove', (e) => { if (!isDragging) return; const diffX = e.clientX - startX; const newAngle = startRotation - diffX * 0.5; // 使用requestAnimationFrame优化性能 if (lastAnimationFrameId) { cancelAnimationFrame(lastAnimationFrameId); } lastAnimationFrameId = requestAnimationFrame(() => { currentAngle = newAngle; rotateCarousel(currentAngle); }); }); document.addEventListener('mouseup', () => { if (isDragging) { isDragging = false; document.body.style.cursor = 'default'; document.body.style.userSelect = ''; if (lastAnimationFrameId) { cancelAnimationFrame(lastAnimationFrameId); } } }); activityBtn.addEventListener('click', () => { createActivityList(); activityModal.style.display = 'block'; // 添加延迟以确保过渡效果生效 setTimeout(() => { activityModal.classList.add('modal-open'); }, 10); }); closeBtn.addEventListener('click', () => { activityModal.classList.remove('modal-open'); // 等待过渡完成后隐藏模态框 setTimeout(() => { activityModal.style.display = 'none'; }, 500); }); window.addEventListener('click', (e) => { if (e.target === activityModal) { activityModal.classList.remove('modal-open'); // 等待过渡完成后隐藏模态框 setTimeout(() => { activityModal.style.display = 'none'; }, 500); } }); createCarouselItems(); rotateCarousel(currentAngle); }); </script> </body> </html> 如何调整transform的值,使得所有的<div class="carousel-info"><h3 class="carousel-title">端午节福利发放</h3><p class="carousel-desc">行政部: 全体成员、各部门代表</p></div>都可以显示?
07-11
不改变内容添加高亮 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> body { margin: 0; padding: 0; } .right { width: 400px; height: 100%; position: fixed; right: 0; top: 0; background-color: rgba(0, 0, 0, 0.1); } .right>.head>div { float: left; width: 50%; text-align: center; height: 40px; line-height: 40px; background-color: #389fc3; color: white; } .right>.head>.time { background-color: white; color: red; } .right>.head, .right>.title, .right>.content { width: 280px; border: 1px solid #ccc; } .right>.title>span { font-size: 12px; display: inline-block; width: 50%; text-align: center; height: 40px; line-height: 40px; } .right>.title>span:first-child { font-size: 14px; font-weight: 500; } .right>.content { list-style: none; margin: 0; padding: 0 0 0 5px; width: 275px; } .right>.content>li { width: 30px; height: 30px; border: 1px solid #ccc; float: left; font-size: 12px; text-align: center; line-height: 30px; margin: 5px; } .right>.content>li>a { display: block; width: 100%; height: 100%; text-decoration: none; color: black; } .right>.content>li.active { background-color: #5d9cec; color: white; } .bottom { width: 900px; position: fixed; height: 40px; bottom: 0; right: 400px; line-height: 40px; padding-left: 20px; background-color: rgba(0, 0, 0, 0.1); } .bottom>.time { color: red; } .bottom>.submit { width: 100px; height: 100%; float: right; background-color: #389fc3; color: white; text-align: center; cursor: pointer; } .clear::after { content: ""; display: block; clear: both; height: 0; overflow: hidden; opacity: 0; } .main { margin-top: 10px; border: 1px solid #ccc; width: 900px; position: relative; left: 110px; } .main-title { height: 40px; line-height: 40px; } .main-title>span:first-child { padding: 0 20px; } .main-title>.main-sorce { display: inline-block; color: white; font-size: 12px; background-color: #389fc3; border-radius: 20px; padding: 0 10px; } .main>.main-question { list-style: none; margin: 0; padding: 0; } .main>.main-question>li { padding: 20px 0; } .main>.main-question .left { float: left; width: 50px; } .main>.main-question .left>span { width: 30px; height: 30px; background-color: #5d9cec; display: inline-block; border-radius: 30px; text-align: center; color: white; line-height: 30px; margin-left: 10px; } .main>.main-question .question { float: left; padding-left: 30px; width: 80%; } .main>.main-question .question>.line { width: 100%; border-top: 0.5px solid #000; } .main>.main-question .question>ul { list-style: none; margin: 0; padding: 0; } .main>.main-question .question>ul>li { padding: 5px; } .main>.main-question .question>ul>li:hover { background-color: #eee; } .mask { width: 100%; height: 100%; position: fixed; background-color: rgba(0, 0, 0, 0.4); z-index: 999; left: 0; top: 0; display: none; } .mask>.score-panel { width: 50%; height: 50%; position: absolute; left: 0; top: 0; right: 0; bottom: 0; margin: auto; background-color: white; } </style> </head> <body> <div class="main"> <div class="main-title"> <span>单选题</span> <span class="main-sorce">共0题,合计0分</span> </div> <ul class="main-question"></ul> </div> <div class="right"> <div class="head clear"> <div>答题卡</div> <div class="time">00:00:00</div> </div> <div class="title"><span>单选题</span><span class="num">共0道</span></div> <ul class="content clear"></ul> </div> <div class="bottom clear"> <span class="time">00:00:00</span> <div class="submit">提交</div> </div> <div class="mask"> <div class="score-panel"></div> </div> <script type="module"> import getTime from "../js/time.js"; import questionList from "../js/data.js"; // 定义全局变量 var times, num, score, content, mainQuestion, submit, mask; var answerList = {}; // 存储用户答案的对象 {题目索引: 答案} // 初始化应用 init(); // 初始化函数 function init() { // 获取所有计时器元素 times = document.querySelectorAll(".time"); // 为每个计时器设置120秒倒计时 times.forEach((item) => getTime(120, item)); // 设置分数显示 setScore(); // 设置右侧题目导航 setRightContent(); // 创建题目内容 createQuestion(); // 绑定提交事件 submitAnswer(); } // 设置分数信息 function setScore() { // 获取题目数量和分数显示元素 num = document.querySelector(".num"); score = document.querySelector(".main-sorce"); // 显示总题数 num.innerHTML = `共${questionList.length}题`; // 计算总分 var s = questionList.reduce((value, item) => value + item.score, 0); // 显示总分信息 score.innerHTML = `共${questionList.length}题,合计${s}分`; } // 创建右侧题目导航 function setRightContent() { // 获取导航容器 content = document.querySelector(".content"); // 生成题目导航链接 content.innerHTML = questionList .map((item, index) => { // 为每个题目创建带锚点的链接 return `<li><a href='#${index}'>${index + 1}</a></li>`; }) .join(""); } // 创建题目内容 function createQuestion() { // 获取题目容器 mainQuestion = document.querySelector(".main-question"); // 绑定题目点击事件委托 mainQuestion.addEventListener("click", questionHandler); // 生成所有题目HTML mainQuestion.innerHTML = questionList .map((item, index) => { return ` <li class="clear" id='${index}'> <div class="left"><span>${index + 1}</span></div> <div class="question"> <div>${item.question}</div> <div class="line"></div> <ul> ${item.options .map((t, ind) => { // 生成选项(A/B/C/D) const optionChar = String.fromCharCode(65 + ind); return `<li> <input type="radio" name="${index}" data='${optionChar}'/> ${optionChar + "." + t} </li>`; }) .join("")} </ul> </div> </li> `; }) .join(""); } // 处理题目选择 function questionHandler(e) { // 只处理input元素的点击 if (e.target.nodeName !== "INPUT") return; const name = e.target.name; // 获取题目索引 const data = e.target.getAttribute("data"); // 获取选项值(A/B/C/D) // 存储答案 {题目索引: 选项} answerList[name] = data; } // 提交功能初始化 function submitAnswer() { // 获取提交按钮和遮罩层 submit = document.querySelector(".submit"); mask = document.querySelector(".mask"); // 绑定提交事件 submit.addEventListener("click", clickHandler); // 绑定遮罩层点击事件 mask.addEventListener("click", maskHiddenHandler); } // 提交按钮点击处理 function clickHandler(e) { // 显示分数面板 mask.style.display = "block"; // 计算得分 const totalScore = Object.keys(answerList).reduce((value, key) => { const questionIndex = Number(key); // 答案正确时累加分数 if (questionList[questionIndex].result === answerList[key]) { value += questionList[questionIndex].score; } return value; }, 0); // 显示得分 document.querySelector(".score-panel").innerHTML = `您一共得了${totalScore}分`; } // 关闭分数面板 function maskHiddenHandler(e) { mask.style.display = "none"; } </script> </body> </html>
最新发布
08-02
<?php include './include/class.main.php'; include './save/config.php'; include './save/top.inc.php'; $skin=array( 'color'=>'#50b2c8', //文本颜色 'input_border'=>'#6599aa', //搜索边框颜色 'input_color'=>'white', //搜索文本颜色 'background'=>'#0f3854', //背景颜色 'background_style'=>'#0a2e38 0%,#000000 80%', //背景渐变样式 ); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="renderer" content="webkit"/> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/> <script type="text/javascript" src="./include/jquery.min.js"></script> <script type="text/javascript" src="./include/class.main.js" ></script> <link href="./include/jquery.autocomplete.css" rel="stylesheet"> <script type="text/javascript" src="./include/jquery.autocomplete.js?ver=1.2"></script> <title><?php echo $CONFIG["TITLE"]; ?></title> <style> html,body{ overflow:auto !important; width:100%; height: 100%; margin: 0; padding: 0; } body{ text-align: center; background: <?php echo $skin["background"];?>; background: -webkit-radial-gradient(<?php echo $skin["background_style"];?>); /* Safari 5.1-6.0 */ background: -o-radial-gradient(<?php echo $skin["background_style"];?>); /* Opera 11.6-12.0 */ background: -moz-radial-gradient(<?php echo $skin["background_style"];?>); /* Firefox 3.6-15 */ background: radial-gradient(<?php echo $skin["background_style"];?>); /* 标准语法 */ background-size: 100%; } p { margin: 0; padding: 0; } a{ color:<?php echo $skin["color"]; ?>; } #clock { font-family: 'Share Tech Mono', monospace; text-align: center; color: #daf6ff; /* text-shadow: 0 0 20px #0aafe6, 0 0 20px rgba(10, 175, 230, 0); */ } #clock .time { letter-spacing: 0.05em; font-size: 60px; padding: 5px 0; } #clock .date { letter-spacing: 0.1em; font-size: 15px; } #clock .text { letter-spacing: 0.1em; font-size: 12px; padding: 20px 0 0; } #word{ background: #fff; color: #000; max-height:170px; overflow-y:auto; overflow-x:hidden; } #main{ text-align: center; background-size: cover } h1{ color:red;} h2{color:green;} h3{color:#a7e9c3} h4{color:blue;font-size:50px} *{ box-sizing: border-box;} div.search {padding: 5px 0;} form { position: relative; width: 300px; margin: 0 auto; } input, button { border: none; outline: none; color:<?php echo $skin["input_color"]; ?>; } input { width: 100%; height: 42px; padding-left: 13px; } button { height: 42px; width: 42px; cursor: pointer; position: absolute; } /*搜索框6*/ .bar6 input { background: transparent; border-radius:3px; border:2px solid <?php echo $skin["input_border"]; ?> ; top: 0; right: 0; } .bar6 button { background:<?php echo $skin["input_border"]; ?>; border-radius: 0 5px 5px 0; width: 60px; top: 0; right: 0; } .bar6 button:before { content: "搜索"; font-size: 13px; color: <?php echo $skin["input_color"] ?>; } /* 搜索内容样式 */ .list_btn{ display: inline-block; text-decoration: inherit; /* 内外边距及宽高属性 */ margin: 1%; padding: 5px; height: 30px; min-width:31%; max-width:95%; /* 文字及边框属性 */ color:<?php echo $skin["color"]; ?>; font-size:13px; border-radius: 5px; border: 2px solid <?php echo $skin["color"]; ?>; /* 文字剪裁 */ text-overflow: ellipsis; overflow: hidden; white-space: nowrap !important; outline: 0 !important } /* 移动设备自适应宽高 */ @media screen and (max-width: 650px){.list_btn{min-width:95%;}} /*清除浮动代码*/ .clearfloat{clear:both} .resou{ padding-top: 15px; } .resou a{ color:<?php echo $skin["color"] ?>; padding: 5px; text-decoration:none; } a{text-decoration:none;} </style> <script> function check_str(field){ with(field){ var arr=['{','}','(',')','=',',',';','"','<','>','script','iframe','@','&','%','$','#','*',':','.','if','/','\\']; if("<?php echo $CONFIG["socode"]["not_off"];?>"=='1'){ var str="<?php echo base64_decode($CONFIG["socode"]["not_val"]); ?>"; if(str!=''){strs = str.split("|");arr = arr.concat(strs);} } for (var key in arr) { if( value.toLowerCase().indexOf(arr[key].toLowerCase()) > -1){ return true; } } return false; } } function validate_form(thisform){ with(thisform){ if(wd.value.indexOf('http')===-1){action='./so.php';wd.name='wd'}else{action='./';wd.name='url';} if(typeof wd!=="undefined" && wd.name=='wd'){ if (check_str(wd)){ alert("请勿输入非法字符!"); return false } } } } </script> <!--<script type="text/javascript" src="../../../include/jquery.min.js"></script>--> <script> // 检查是否为移动设备 function isMobileDevice() { return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); } // 加载随机背景图片 function loadRandomBackground() { if(isMobileDevice()) { var backgroundURL = './208896.jpg' } else { backgroundURL = './208899.jpg' } console.log(backgroundURL) // 设置body的背景图片为随机图片 $('body').css('background', 'url(' + backgroundURL + ') no-repeat center center fixed'); $('body').css('background-size', 'cover'); } // 页面加载时加载随机背景 $(document).ready(function() { loadRandomBackground(); }); </script> </head> <body> <div id="clock"> <div id="main"></div> <div class="clearfloat"></div> <div id='body'> <p class="date"></p> <p class="time" id="time">00:00:00</p> <p class="text" id="text">2018-08-08 星期一</p><br> <div class="search bar6"> <form target="_parent" action="./" onsubmit="return validate_form(this);" method="get" > <input id="wd" type="text" name="v" placeholder="请输入视频名称或视频链接" value="<?php echo $_GET['wd']; ?>" > <button type="submit"></button> <div id="word" ></div> </form> <?php if($CONFIG["socode"]["top_off"]): ?> <div class="resou" id="socode_top"> <font face="verdana" style="color:<?php echo $skin["color"] ?>;"> 热门搜索:</font> <?php arsort($TOPDATA);$i=0; foreach ($TOPDATA as $key=>$val ): ?> <a target='_parent' href="./so.php?wd=<?php echo rawurlencode($key); ?>" title='人气:<?php echo $val; ?>℃'><?php echo $key; ?></a> <?php $i++; if($i==5){break;}?> <?php endforeach; ?> <a target='_parent' href="javascript:void(0);" onclick="echotop();">更多...</a> </div> <?php endif; ?> <?php if($CONFIG["socode"]["diy_off"]): ?> <div id="socode_diy"> <br/> <?php echo base64_decode($CONFIG["socode"]["diy_val"]); ?> </div> <?php endif; ?> </div> <script id="LA-DATA-WIDGET" crossorigin="anonymous" charset="UTF-8" src="https://v6-widget.51.la/v6/JmppOQcqqd5xRMl7/quote.js?theme=#0EEBF2,#333333,#04F2EA,#333333,#FFFFFF,#1690FF,12&f=12&display=0,1,0,1,0,1,0,1"></script> <?php if($CONFIG["FOOTER_LINK"]['off']): ?> <div id="footer_link"> <br/> <font face="verdana" style="color:<?php echo $skin["color"] ?>;"> 友情链接:</font> <?php foreach( $CONFIG["FOOTER_LINK"]['info'] as $key=>$val) : ?> <a target='_blank' href="<?php echo $val; ?>" ><?php echo $key; ?></a> <?php endforeach; ?> </div> <?php endif; ?> <br><span id="sitetime"> </span><br> <br><div id="footer" ></div> </div> </div> <script> //显示日期时间 var week = ['星期天', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']; var timerID = setInterval(updateTime, 1000); var sitetime="<?php echo $CONFIG["sitetime"];?>"; updateTime(); function updateTime() { var cd = new Date(); $('#time').text(zeroPadding(cd.getHours(), 2) + ':' + zeroPadding(cd.getMinutes(), 2) + ':' + zeroPadding(cd.getSeconds(), 2)); $('#text').text(zeroPadding(cd.getFullYear(), 4) + '-' + zeroPadding(cd.getMonth()+1, 2) + '-' + zeroPadding(cd.getDate(), 2) + ' ' + week[cd.getDay()]); SiteTime(sitetime); }; function zeroPadding(num, digit) { var zero = ''; for(var i = 0; i < digit; i++) { zero += '0'; } return (zero + num).slice(-digit); } //网站运行时间 function SiteTime(time){ var seconds =1000; var minutes = seconds *60; var hours = minutes *60; var days = hours *24; var years = days *365; var dateBegin = new Date(time.replace(/-/g, "/"));//将-转化为/,使用new Date var dateEnd = new Date();//获取当前时间 var diff = dateEnd.getTime() - dateBegin.getTime();//时间差的毫秒数; var diffYears =Math.floor(diff/years); var diffDays =Math.floor((diff/days)-diffYears*365); var diffHours =Math.floor((diff-(diffYears*365+diffDays)*days)/hours); var diffMinutes =Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes); var diffSeconds =Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds); document.getElementById("sitetime").innerHTML=" 已运行"+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒"; } </script> <script> //入口 function init() { var wd= _GET("wd"); var url= _GET("url"); if(wd==="" && url==="" ){ //w="...请输入视频地址... "; w='<br><br><font size="4" color="<?php echo $skin["color"] ?>">...视</font><font color="<?php echo $skin["color"] ?>">频地址不能为空...</font>'; $(".date").html(w); } if(wd!==""){getvideo(wd);} w="<?php echo $CONFIG["play"]["all"]["by"]; ?>"; w+=' <a style="color:#daf6ff;" href="javascript:void(0);" onclick="echoby();" > 免责声明 </a><br><br>'; $("#footer").html(w); toggleCenter(); } //显示版权 function echoby() { alert("本站所有视频均来自外部引用,本站不存储不制作任何视频!\r\n 如有侵权问题,请与源站联系,谢谢合作!"); } //搜索排行 function echotop(){ if ($("#main").html().indexOf("搜索排行榜")!=-1){ $("#main").html(""); }else{ var w = "<br><br><div style='text-align:center;'><h3>搜索排行榜-TOP100</h3>"; <?php arsort($TOPDATA);$i=0; foreach ($TOPDATA as $key=>$val ): ?> title="<?php echo $key; ?>"; w+= "<a target='_parent' class='list_btn' href='./so.php?wd=<?php echo rawurlencode($key); ?>' title='人气:<?php echo $val; ?>℃'><strong>" + title+ "</strong></a>"; <?php $i++; if($i==100){break;}?> <?php endforeach; ?> w+= "</div>"; $("#main").html(w); } toggleCenter(); } //刷新列表 function relist(data){ if(data&&data.success) { var v=data.info; var w = "<br><br><div style='text-align:center;'><h3>搜索到相关视频" + v.length + "个,请点击访问</h3>"; for (i = 0, len = v.length; i < len; i++) { /* _blank:新窗口打开。 _parent:在父窗口中打开链接。 _self:默认,当前页面跳转。 _top:在当前窗体打开链接,并替换当前的整个窗体(框架页)。 */ var href="./?index"+v[i].id +"-" + v[i].flag+"-1.htm"; var title=removeHTMLTag(v[i].title,true)+"(" +(v[i].from)+")"; w+= "<a class='list_btn ' target='_self' href='" +href +"' title='"+ title+"' ><strong>" + title + "</strong></a>"; } w+= "</div>"; }else{ var w='<h3 >很抱歉,未搜索到相关资源</h3>'; $("#info").html('请修改影片名后重新搜索'); } $("#main").html(w); $("#body").show(); toggleCenter(); } //取视频数据 function getvideo(word){ $.ajax({ url: './<?php echo $CONFIG["API_PATH"]; ?>?out=jsonp&wd='+word, timeout:30000, dataType: 'jsonp', jsonp: 'cb', beforeSend: function() { $("#body").hide(); $("#main").html('<h3 >正在搜索中,请稍后...</h3>'); }, success: function (data) { relist(data); }, error: function () { relist(); } }); } //自适应大小位置 function toggleCenter() { if($("#main").height() + $("#clock").height()>$(window).height()){ $("#clock").css("position","static"); }else{ $("#clock").css("position","absolute");$("#clock").css("top",($(window).height() -$("#clock").height())/2-20); } if($(window).width()<=$("#clock").width()){$("#clock").css("left",0);}else{ $("#clock").css("left",($(window).width()-$("#clock").width())/2);} } $(window).resize(function(){ toggleCenter();}); init(); </script> </body> </html>美化搜索结果页面
06-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值