news 2026/4/18 12:27:45

【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/4/18 11:05:54

Z-Image-Turbo与AutoDL对比:哪种部署方式更适合初学者?

Z-Image-Turbo与AutoDL对比&#xff1a;哪种部署方式更适合初学者&#xff1f; 1. 初学者最关心的问题&#xff1a;到底该选哪个&#xff1f; 刚接触AI图像生成的朋友&#xff0c;常会遇到一个现实困惑&#xff1a;Z-Image-Turbo和AutoDL都号称“一键部署”&#xff0c;但一个…

作者头像 李华
网站建设 2026/4/18 8:50:22

常见的Maven命令

一、Maven的简介Maven是Apache开源基金会提供的适合Java语言项目管理的工具。Maven本身需要Java运行环境的支持。二、主要功能1、清除编译文件。2、打包成jar或者war部署文件。3、编译源代码。4、启动程序。5、安装到本地仓库。6、部署到远程仓库。三、主要的命令注意&#xff…

作者头像 李华
网站建设 2026/3/31 21:13:02

【C++高性能并发编程终极指南】:掌握Boost.Asio与Boost.Thread核心技巧

第一章&#xff1a;C高性能并发编程概述 在现代计算环境中&#xff0c;多核处理器已成为标准配置&#xff0c;如何充分利用硬件资源实现程序的高效执行成为系统性能优化的关键。C作为系统级编程语言&#xff0c;提供了强大的底层控制能力和丰富的并发支持机制&#xff0c;使其成…

作者头像 李华
网站建设 2026/4/18 8:47:33

[STM32C0] 【STM32C092RC 测评】3、板载外设——GPIO和定时器

我们在这里进行GPIO和定时器的测试&#xff0c;把这两个外设功能融合一起主要也是为了比较好展示&#xff0c;定时器属于内部模块&#xff0c;如果只是定时器的定时功能&#xff0c;实际上是不需要任何其他实际端口的&#xff0c;另一方面他也和其他外设比较容易融合。比如我们…

作者头像 李华
网站建设 2026/4/18 0:19:25

你真的了解点击劫持漏洞吗?深度解析与防御策略

你真的了解点击劫持漏洞吗&#xff1f; 我听过许多关于点击劫持的版本&#xff0c;但没有人能真正把它解释清楚。 点击劫持的核心思想 点击劫持的核心思想在于&#xff1a; 目标网站&#xff1a;执行敏感操作的一方&#xff08;例如“支付”、“更改设置”按钮所在的网站&a…

作者头像 李华
网站建设 2026/4/18 6:47:07

线上故障紧急处理手册:如何在不重启的情况下用jstack救活死锁应用

第一章&#xff1a;线上故障紧急处理手册的核心价值 在现代分布式系统架构中&#xff0c;线上服务的稳定性直接关系到企业声誉与用户信任。面对突发性故障&#xff0c;响应速度与处理效率成为关键指标&#xff0c;而《线上故障紧急处理手册》正是提升应急响应能力的核心工具。它…

作者头像 李华