產品列表縮圖排列,滑鼠移入單張圖片平滑放大(寬度從原尺寸擴大至 300px、高度 150px),移出平滑縮回原尺寸,不影響周圍版面。純視覺操作,零 JavaScript 手寫。

















800x299px,overflow: hidden 裁切溢出,確保放大不撐破版面。im1~im5),綁定 4 個「變更屬性」行為。#333) 利於圖片展示。container → CSS 設定:width:800px; height:299px; overflow:hidden; position:absolute; left:50%; top:50%; margin:-150px 0 0 -400px;(置中)。gallery → 置入 container 內部中心 → 插入 1 行 5 列表格,寬度 100%。以第一張圖片 im1 為例:
im1。imgim1width300(目標放大寬度)onmouseover(滑鼠移入)height → 新值 150 → 事件 onmouseover。width → 新值 150(原始寬度) → 事件 onmouseout(滑鼠移出)。height → 新值 100(原始高度) → 事件 onmouseout。對剩餘 4 張圖片 (im2~im5) 重複上述 4 步驟,只需修改元素 ID 與原始尺寸值。
| 事件 | 動作 | 目標元素 | 屬性 | 新值 |
|---|---|---|---|---|
| onmouseover | Change Property | img#im1 | width | 300 |
| onmouseover | Change Property | img#im1 | height | 150 |
| onmouseout | Change Property | img#im1 | width | 150 |
| onmouseout | Change Property | img#im1 | height | 100 |
overflow: hidden,否則圖片放大會撐大容器、推擠版面。transition: width 0.3s, height 0.3s; 或 JS 動畫庫。transform: scale(1.5)(僅合成層,不觸發重排)+ transition。<style>
.gallery { display: flex; gap: 10px; overflow-x: auto; padding: 10px; }
.gallery img {
width: 150px; height: 100px; object-fit: cover; flex-shrink: 0;
transition: transform 0.3s ease, z-index 0s 0.3s;
cursor: zoom-in;
}
.gallery img:hover, .gallery img:focus {
transform: scale(2);
z-index: 10;
outline: none;
box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
</style>
<div class="gallery">
<img src="img1.jpg" alt="產品1">
<img src="img2.jpg" alt="產品2">
<img src="img3.jpg" alt="產品3">
<img src="img4.jpg" alt="產品4">
<img src="img5.jpg" alt="產品5">
</div>
優勢:零 JS、GPU 加速、響應式、無障礙支援焦點狀態、程式碼極簡。
Dreamweaver「變更屬性」行為提供零代碼快速原型驗證,適合靜態展示、簡報原型。正式專案請採用 CSS Transform + Transition 方案,兼顧效能、動畫品質、無障礙與維護性。理解兩種方案的權衡,才能根據專案階段做出最佳技術選型。