当前位置: 首页 > news >正文

【Svelte】像 vs code 一样的布局:三栏布局

直接贴代码:

<scriptlang="ts">import{browser}from'$app/environment';import{onMount}from'svelte';// Layout stateletleftWidth=$state(33.33);letmiddleWidth=$state(33.33);letisResizingLeft=$state(false);letisResizingRight=$state(false);onMount(()=>{consthandleMouseMove=(e:MouseEvent)=>{constcontainer=document.getElementById('layout-container');if(!container)return;constcontainerRect=container.getBoundingClientRect();constcontainerWidth=containerRect.width;constmouseXRelativeToContainer=e.clientX-containerRect.left;if(isResizingLeft){constnewLeftWidth=(mouseXRelativeToContainer/containerWidth)*100;constcurrentRightBoundary=leftWidth+middleWidth;// Ensure minimum widths of 5% and that we don't cross the second resizerif(newLeftWidth>5&&newLeftWidth<currentRightBoundary-5){leftWidth=newLeftWidth;middleWidth=currentRightBoundary-newLeftWidth;}}elseif(isResizingRight){constleftBoundaryPx=(leftWidth/100)*containerWidth;constnewMiddleWidth=((mouseXRelativeToContainer-leftBoundaryPx)/containerWidth)*100;// Ensure middle column doesn't get too small (min 5%)// and doesn't push the right column below 5%if(newMiddleWidth>5&&(leftWidth+newMiddleWidth)<95){middleWidth=newMiddleWidth;}}};consthandleMouseUp=()=>{isResizingLeft=false;isResizingRight=false;document.body.style.cursor='default';};window.addEventListener('mousemove',handleMouseMove);window.addEventListener('mouseup',handleMouseUp);return()=>{window.removeEventListener('mousemove',handleMouseMove);window.removeEventListener('mouseup',handleMouseUp);};});</script><divid="layout-container"class="flex h-[calc(100vh-64px)] w-full overflow-hidden bg-white"style="user-select:{isResizingLeft || isResizingRight ?'none':'auto'}"><!-- Column 1 --><divclass="flex h-full flex-col border-r-4 border-black bg-red-100 shrink-0"style="flex: 0 0{leftWidth}%"><divclass="p-8"><h1class="text-4xl font-black text-red-600">COLUMN 1 - LEFT</h1><pclass="mt-4 text-xl">If you can see this, the layout is working.</p></div></div><!-- Resizer 1 --><div class="z-10 w-2 cursor-col-resize bg-black hover:bg-primary shrink-0" onmousedown={() => { isResizingLeft = true; document.body.style.cursor = 'col-resize'; }} ></div><!-- Column 2 --><divclass="flex h-full flex-col border-r-4 border-black bg-blue-100 shrink-0"style="flex: 0 0{middleWidth}%"><divclass="p-8"><h1class="text-4xl font-black text-blue-600">COLUMN 2 - MIDDLE</h1><pclass="mt-4 text-xl">Drag the black bars to resize.</p></div></div><!-- Resizer 2 --><div class="z-10 w-2 cursor-col-resize bg-black hover:bg-primary shrink-0" onmousedown={() => { isResizingRight = true; document.body.style.cursor = 'col-resize'; }} ></div><!-- Column 3 --><divclass="flex h-full flex-grow flex-col bg-green-100 min-w-0"><divclass="p-8"><h1class="text-4xl font-black text-green-600">COLUMN 3 - RIGHT</h1><pclass="mt-4 text-xl">Everything should be visible now.</p></div></div></div><style>:global(body){user-select:none;/* Prevent text selection while resizing */}</style>
http://www.jsqmd.com/news/278889/

相关文章:

  • cv_unet_image-matting能否集成到网站?Web服务封装教程
  • Open-AutoGLM性能实测:不同机型响应速度对比分析
  • TurboDiffusion社交内容应用:用户UGC视频增强实战案例
  • 【C++23新特性全解析】:掌握这10个核心变化,让你的代码性能提升50%
  • Paraformer置信度过低如何判断?结果可信度评估与复核机制设计
  • Z-Image-Turbo与AutoDL对比:哪种部署方式更适合初学者?
  • 图像修复风格一致性:fft npainting lama参考图像技巧
  • C++ vector扩容策略详解:如何避免频繁内存分配提升程序效率
  • 麦橘超然广告创意案例:海报素材快速生成流程
  • Java获取当前时间戳毫秒级,你真的会用吗?
  • 开源AI绘画2026展望:Z-Image-Turbo引领本地化部署新浪潮
  • 揭秘C语言读写二进制文件:99%程序员忽略的关键细节
  • 麦橘超然与Midjourney对比:开源VS云端绘图成本全面评测
  • Paraformer-large如何提升识别率?VAD与Punc模块集成实战详解
  • CAM++是否支持英文?跨语言验证测试结果公布
  • 好写作AI:别再拿AI当“高级Word”用了!这才是降维打击
  • TurboDiffusion模型切换机制:高噪声与低噪声阶段分工解析
  • PyTorch镜像部署卡GPU?CUDA适配问题保姆级教程来解决
  • 中文界面友好度评分:科哥构建版用户体验细节优化
  • 线上故障紧急处理手册:如何在不重启的情况下用jstack救活死锁应用
  • 2025年末河北粘钉一体机厂家大揭秘,口碑王者花落谁家?目前粘钉一体机找哪家关键技术和产品信息全方位测评
  • 好写作AI:从“搬砖思维”到“建筑师思维”,AI如何重构你的学术大脑?
  • 2026年河南精铸工匠不锈钢有限公司联系电话推荐:精选推荐与使用指南
  • Open-AutoGLM入门必看:手机AI Agent三大核心组件解析
  • 2026年银源电力联系电话推荐:精选推荐与使用指南
  • 揭秘CMake引入第三方库的5大陷阱:90%开发者都会踩的坑,你中招了吗?
  • 如何快速上手YOLO11?保姆级教程带你30分钟完成部署
  • 深聊东辉实业的创新成果多吗,研发成果大盘点
  • 【高并发场景必备】:Stream filter多条件性能优化的4个关键点
  • 泛型方法为何不能重载?从字节码层面揭开擦除机制的神秘面纱