js+css实现小学生可视化拖拽电子元器件做电路实验代码
代码语言:html
所属分类:其他
代码描述:js+css实现小学生可视化拖拽电子元器件做电路实验代码,拖拽后点击元器件左右点进行连线。
代码标签: js css 小学生 可视化 拖拽 电子 元器件 电路 实验 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!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;
}
body {
font-family: 'Microsoft YaHei', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
overflow: hidden;
}
.header {
text-align: center;
padding: 10px;
color: white;
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}
.header h1 {
font-size: 28px;
margin-bottom: 5px;
}
.header p {
font-size: 14px;
opacity: 0.9;
}
.main-container {
display: flex;
height: calc(100vh - 80px);
padding: 0 10px 10px;
gap: 10px;
}
.toolbox {
width: 180px;
background: rgba(255,255,255,0.95);
border-radius: 16px;
padding: 15px;
box-shadow: 0 8px 32px rgba(0,0,0,0.2);
overflow-y: auto;
}
.toolbox h3 {
text-align: center;
color: #333;
margin-bottom: 10px;
font-size: 16px;
border-bottom: 2px solid #667eea;
padding-bottom: 8px;
}
.tool-item {
display: flex;
flex-direction: column;
align-items: center;
padding: 10px;
margin-bottom: 8px;
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
border-radius: 12px;
cursor: grab;
transition: all 0.3s;
border: 2px solid transparent;
user-select: none;
}
.tool-item:hover {
transform: scale(1.05);
border-color: #667eea;
box-shadow: 0 4px 15px rgba(102,126,234,0.3);
}
.tool-item:active {
cursor: grabbing;
}
.tool-icon {
width: 60px;
height: 60px;
margin-bottom: 5px;
}
.tool-item span {
font-size: 13px;
color: #555;
font-weight: bold;
}
.canvas-area {
flex: 1;
background: rgba(255,255,255,0.95);
border-radius: 16px;
box-shadow: 0 8px 32px rgba(0,0,0,0.2);
position: relative;
overflow: hidden;
}
.canvas-area svg.wires-layer {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 1;
}
.component {
position: absolute;
cursor: move;
z-index: 10;
user-select: none;
}
.component:hover {
filter: brightness(1.1);
}
.component svg {
pointer-events: none;
}
.terminal {
position: absolute;
width: 20px;
height: 20px;
border-radius: 50%;
background: #e74c3c;
border: 3px solid #c0392b;
cursor: crosshair;
z-index: 20;
transition: all 0.2s;
}
.terminal:hover, .terminal.highlight {
transform: scale(1.4);
background: #2ecc71;
border-color: #27ae60;
box-shadow: 0 0 10px rgba(46,204,113,0.6);
}
.terminal.connected {
background: #3498db;
border-color: #2980b9;
}
.wire-drawing {
stroke: #333;
stroke-width: 4;
fill: none;
stroke-linecap: round;
pointer-events: none;
}
.wire {
stroke-width: 4;
fill: none;
stroke-linecap: round;
cursor: pointer;
pointer-events: stroke;
transition: stroke 0.3s;
}
.wire:hover {
stroke-width: 6;
filter: drop-shadow(0 0 4px rgba(0,0,0,0.3));
}
.wire.powered {
stroke: #f39c12;
filter: drop-shadow(0 0 6px rgba(243,156,18,0.6));
animation: pulse-wire 1s infinite alternate;
}
@keyframes pulse-wire {
from { filter: drop-shadow(0 0 4px rgba(243,156,18,0.4)); }
to { filter: drop-shadow(0 0 10px rgba(243,156,18,0.8)); }
}
.controls {
position: absolute;
top: 10px;
right: 10px;
display: flex;
gap: 8px;
z-index: 30;
}
.btn {
padding: 8px 16px;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 14px;
font-weight: bold;
transition: all 0.3s;
font-family: 'Microsoft YaHei', sans-serif;
}
.btn-check {
background: linear-gradient(135deg, #2ecc71, #27ae60);
color: white;
}
.btn-reset {
background: linear-gradient(135deg, #e74c3c, #c0392b);
color: white;
}
.btn-help {
background: linear-gradient(135deg, #3498db, #2980b9);
color: white;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
..........完整代码请登录后点击上方下载按钮下载查看
















网友评论0