Crafting a personalized accordion involves utilizing a dropdown element and interactions. This tutorial will cover:
- How to insert a dropdown element
- How to customize your dropdown switch
- How to design your accordion
- How to produce your bespoke animation
How to include a dropdown element
這 drop-down element contains default built-in functions that simplify its use as a personalized accordion — it uncovers the 下拉清單 upon click and conceals it upon clicking a distinct element or part of the page.
You can integrate a drop-down element into your website by navigating to 新增面板 (A) > 元素 > 先進的 and dragging the drop-down element onto the canvas.
How to modify the default drop-down styles
To incorporate the dropdown in your personalized accordion, you must adjust the default dropdown element styles. Particularly, you ought to modify the width to ensure the dropdown occupies the entire space of its parent element (i.e., the element containing the custom accordion).
Bonus tip: 分配一個 班級 to your dropdown (e.g., “Accordion item”) for reusability in styling. Explore more about styling using classes.
To adjust the default dropdown styles:
- Choose the parent drop-down element on the Designer canvas (we designated it a class of “Accordion item” in this instance)
- 訪問 風格面板 > 尺寸
- Specify 寬度 作為 100%
How to personalize your drop-down switch
At this moment, you need to personalize your drop-down switch so it completely fills its parent element (i.e., the container) and conceals the content within the drop-down list when the accordion is closed. To accomplish this, tweak the drop-down switch’s 展示 和 高度 properties:
- 選擇 drop-down switch on the canvas and assign a class (e.g., “Accordion toggle”)
- 導航 風格面板 > 佈局
- 放 展示 到 彈性盒 for full horizontal coverage
- 放 對齊 到 中心 for vertical text centering on your accordion
- 繼續 風格面板 > 尺寸
- 定義一個 高度 value (e.g., 80px)
How to design your accordion
After this stage, if you test your site and interact with your accordion, you might observe that the accordion unfolds, yet the default content within may overlap surrounding content. This occurs because the default 位置 style for the drop-down list is 絕對. While this is the desired behavior for conventional drop-down usage like in menus or navbars, for your personalized accordion, you must alter the default positioning so the nearby content adjusts (e.g., shifts down or up) when the content inside the accordion expands.
To innovate your accordion:
- Choose the parent drop-down element on the canvas (e.g., the “Accordion item”)
- 選擇“齒輪” icon to unveil Dropdown settings and tap “展示」 毗鄰 導航
- 選擇 List Box option on the artboard
- 導航 設計面板 > 結盟
- 調整 結盟 到 固定的
- Pick the ancestor dropdown element (e.g., “Accordion item”) on the artboard
- 去 設計面板 > 方面
- 放 Mask 到 concealed to mask any content that goes beyond the accordion area
Steps to design your personalized animation
Now, create a unique animation that will handle both opening and closing your custom accordion with these steps:
- Establish initial actions
- Animate the accordion expansion
- Animate the accordion closure
Establish initial actions
Initiate by crafting 2 initial actions (i.e., styles applied to the element before page load) for your accordion.
First, initiate an initial action for your dropdown:
- 選擇 落下 element on the artboard (e.g., “Accordion item”)
- 導航 Interactivity panel > 元素觸發 並點擊“加” symbol to create a fresh element trigger
- 選擇 Dropdown expands
- 輕敲 選擇一個動作 在下面 Menu reveals
- 選擇 Launch an animation 在下面 Personalized animation
- 點選“加” symbol adjacent to Scheduled animations
- Assign a name to your custom animation (e.g., “Accordion expands”)
- 點選“加” 符號旁邊 活動 to incorporate an action to your animation
- 選擇 規模 在下面 Various
- Mark the “Set as initial state” checkbox under 定時
- 進入一個 高度 value (e.g., 80px) under 規模 that aligns with the height given to your 落下轉變 (e.g., the “Accordion switch”) in the prior steps
- 輕敲 節省
Following that, initiate an initial action for the switch icon:
- 選擇 象徵 inside the dropdown element
- 前往 設計面板 and label your icon class (e.g., “Accordion icon”) — now your animation can influence all instances of the icon
- Select your ancestor 落下 element on the artboard (e.g., “Accordion item”)
- 展開 Interactivity panel
- 選擇 Dropdown expands interaction you crafted in the previous steps
- 點選“齒輪” symbol adjacent to the customized timed animation you crafted previously (e.g., the “Accordion expands” interaction)
- 選擇 圖示 (e.g., “Accordion icon”)
- 點選“加” 符號旁邊 活動 to set up an initial action for the icon
- 選擇 旋轉 在下面 改變
- Mark the “Set as initial state” checkbox under 定時
- 前往 旋轉 and dial the z-axis 到 0degrees
- 輕敲 節省
Animate the accordion expansion
Next, set up the actions for expanding the accordion that occur simultaneously when the accordion is clicked — the “Accordion item” size will adjust to the content size within it, and the “Accordion icon” will turn 180 degrees.
To alter the size of the “Accordion item” and rotate the “Accordion icon” upon accordion opening:
- Choose the ancestor 落下 element on the artboard (e.g., “Accordion item”)
- 解鎖 Interactivity panel
- 選擇 Dropdown expands interaction you formulated earlier
- 點選“齒輪” symbol adjacent to the customized timed animationyou fashioned in the prior steps (e.g., the “Accordion opens” animation)
- 點選“加” 符號旁邊 行動 to insert an undertaking to your animation
- 選擇 尺寸 之內 各種各樣的
- Deselect the “Set as initial state” checkbox beneath 定時
- 導航 尺寸 and input “汽車” for the 高度 — this corresponds to the height of your accordion to its content inside
- 選擇 圖示 (e.g., “Accordion icon”)
- 點選“加” symbol adjacent to the “Accordion item” 尺寸 action you just established to append another undertaking at that timestamp — this guarantees that both of these undertakings animate concurrently
- 選擇 旋轉 下面 轉換
- 前往 旋轉 並調整 z-axis 到 180degrees — this rotates the icon so that it directs upwards when the accordion opens
- 輕敲 節省
筆記: You have the option to modify the easement (i.e., the acceleration and deceleration of the animation transition) of each action. Obtain more information regarding interpolation, easement, and smoothing.
Animate the accordion closing
Next, you’ll establish an interaction for the accordion closing. This interaction will contain the undertakings that transpire when the accordion item is pressed a second time or when a visitor clicks outside the accordion item — the accordion item will revert to its initial size, and the icon will rotate back to 0 degrees.
To animate the accordion closing:
- Pick the parent 落下 element on the canvas (e.g., “Accordion item”)
- 揭示 互動面板
- 選擇 Dropdown opens interaction you designed in the prior steps
- 輕敲 選擇一個操作 下面 Menu closes
- 選擇 Start animation
- 點選“加” symbol adjacent to Timed animations to craft a customized animation
- Assign a name to your custom animation (e.g., “Accordion closes”)
- 點選“加” symbol to insert an undertaking to your animation
- 選擇 尺寸 下面 各種各樣的
- 輸入一個 高度 value (e.g., 80px) that coincides with the height you allocated to your 落下 element for its initial state in the previous steps
- 選擇 圖示 on the canvas or in the Navigator (e.g., “Accordion icon”)
- 點選“加” symbol adjacent to the “Accordion item” 尺寸 action you just crafted to add another undertaking at that timestamp — this ensures that both of these undertakings animate concurrently
- 選擇 旋轉 下面 轉換
- 前往 旋轉 並調整 z-axis 到 0degrees — this rotates the icon back to its initial position so it directs downwards when the accordion closes
- 輕敲 節省
And that concludes your successful creation of a unique accordion using interactions!
- 包含或消除工作區點和成員 - 2024 年 4 月 15 日
- 定心框總結 - 2024 年 4 月 15 日
- 儲存站點以供日後參考 - 2024 年 4 月 15 日