news 2026/5/6 5:18:23

【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/27 7:53:44

CAM++是否支持英文?跨语言验证测试结果公布

CAM是否支持英文&#xff1f;跨语言验证测试结果公布 1. 引言&#xff1a;一个中文训练的模型&#xff0c;能识别英文语音吗&#xff1f; CAM 是一个基于深度学习的说话人验证系统&#xff0c;由科哥基于达摩院开源模型二次开发并封装为易用的 WebUI 工具。该系统原本设计用于…

作者头像 李华
网站建设 2026/5/1 3:36:54

好写作AI:你的论文搭档已进化,请查收这份“人机协同”新剧本!

还在纠结用AI写论文是“作弊”还是“明智”&#xff1f;格局打开点&#xff01;这已经不是“用不用”的问题&#xff0c;而是 “如何最佳协同” 的时代。好写作AI与你的关系&#xff0c;正从“工具使用”升级为“智慧共生”——欢迎来到未来论文写作的新范式。 好写作AI官方网…

作者头像 李华
网站建设 2026/5/1 0:00:48

Emotion2Vec+ Large能否识别歌曲情感?音乐场景落地挑战分析

Emotion2Vec Large能否识别歌曲情感&#xff1f;音乐场景落地挑战分析 1. 引言&#xff1a;语音情感模型遇上音乐场景的现实考验 你有没有想过&#xff0c;一段欢快的旋律背后&#xff0c;歌手可能正唱着悲伤的歌词&#xff1f;或者一首节奏低沉的曲子&#xff0c;其实表达的…

作者头像 李华
网站建设 2026/5/5 17:55:24

Java时间戳陷阱揭秘:毫秒级获取为何在多线程下失效?

第一章&#xff1a;Java时间戳陷阱揭秘&#xff1a;毫秒级获取为何在多线程下失效&#xff1f; 在高并发场景中&#xff0c;Java开发者常使用 System.currentTimeMillis() 获取当前时间戳。然而&#xff0c;这一看似简单的方法在多线程环境下可能引发意想不到的问题——多个线…

作者头像 李华