news 2026/9/3 1:29:32

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

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
【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>
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/8/28 20:39:49

PyTorch镜像部署卡GPU?CUDA适配问题保姆级教程来解决

PyTorch镜像部署卡GPU&#xff1f;CUDA适配问题保姆级教程来解决 你是不是也遇到过这种情况&#xff1a;兴冲冲拉下最新的PyTorch开发镜像&#xff0c;准备开始训练模型&#xff0c;结果一运行代码&#xff0c;torch.cuda.is_available() 返回 False&#xff1f;明明机器有GPU…

作者头像 李华
网站建设 2026/9/3 0:25:17

学术搜索:高效获取权威文献与研究资源的核心工具

做科研的第一道坎&#xff0c;往往不是做实验&#xff0c;也不是写论文&#xff0c;而是——找文献。 很多新手科研小白会陷入一个怪圈&#xff1a;在知网、Google Scholar 上不断换关键词&#xff0c;结果要么信息过载&#xff0c;要么完全抓不到重点。今天分享几个长期使用的…

作者头像 李华
网站建设 2026/8/29 13:04:00

GPEN处理进度显示原理:批量任务状态轮询机制解析

GPEN处理进度显示原理&#xff1a;批量任务状态轮询机制解析 1. 引言&#xff1a;从用户界面到后台机制的深入探索 当你在使用GPEN图像肖像增强工具进行批量图片修复时&#xff0c;是否曾好奇过界面上那个“处理进度”是如何实时更新的&#xff1f;点击「开始批量处理」后&am…

作者头像 李华
网站建设 2026/8/29 13:12:19

电路设计软件解惑篇,protel电路设计软件难点解答(下)

电路设计软件的作用大家都知道&#xff0c;如果缺少电路设计软件&#xff0c;电路设计工作将难以进行。目前市场上存在几款主流电路设计软件&#xff0c;其中protel电路设计软件更为受用。为帮助大家使用这款电路设计软件&#xff0c;本文将对protel相关难点进行解答。如果你对…

作者头像 李华
网站建设 2026/9/3 0:18:12

【C++开发效率提升秘籍】:手把手教你5步完美集成第三方库到CMake项目

第一章&#xff1a;C开发效率提升的基石——第三方库集成概述 在现代C开发中&#xff0c;手动实现所有功能不仅耗时且容易引入错误。通过集成经过验证的第三方库&#xff0c;开发者能够显著提升开发效率、代码健壮性和项目可维护性。这些库覆盖了从网络通信、数据序列化到并发控…

作者头像 李华
网站建设 2026/9/2 9:24:25

Glyph日志分析场景:系统事件图像化处理部署教程

Glyph日志分析场景&#xff1a;系统事件图像化处理部署教程 1. Glyph是什么&#xff1f;让日志看得更清楚 你有没有试过打开一个几百兆的系统日志文件&#xff0c;密密麻麻的文字像瀑布一样滚下来&#xff0c;根本找不到重点&#xff1f;传统文本分析工具在面对超长上下文时&…

作者头像 李华