国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

目錄
Basic Spinner Using Borders
Custom Spinner with Multiple Dots
Adding Animation to Buttons
Tips for Customization
首頁(yè) web前端 css教程 CSS教程,用于創(chuàng)建加載旋轉(zhuǎn)器和動(dòng)畫(huà)

CSS教程,用于創(chuàng)建加載旋轉(zhuǎn)器和動(dòng)畫(huà)

Jul 07, 2025 am 12:07 AM
css

創(chuàng)建CSS加載旋轉(zhuǎn)器的方法有三種:1. 使用邊框的基本旋轉(zhuǎn)器,通過(guò)HTML和CSS實(shí)現(xiàn)簡(jiǎn)單動(dòng)畫(huà);2. 使用多個(gè)點(diǎn)的自定義旋轉(zhuǎn)器,通過(guò)不同延遲時(shí)間實(shí)現(xiàn)跳動(dòng)效果;3. 在按鈕中添加旋轉(zhuǎn)器,通過(guò)JavaScript切換類(lèi)來(lái)顯示加載狀態(tài)。每種方法都強(qiáng)調(diào)了設(shè)計(jì)細(xì)節(jié)如顏色、大小、可訪問(wèn)性和性能優(yōu)化的重要性,以提升用戶體驗(yàn)。

CSS tutorial for creating loading spinners and animations

Creating loading spinners with CSS is a straightforward way to enhance user experience while content loads. You don't need JavaScript for simple animations — just HTML and CSS. Below are practical methods to build basic and customizable spinners.

CSS tutorial for creating loading spinners and animations

Basic Spinner Using Borders

One of the simplest ways to create a spinner is by using a bordered element and rotating it with CSS animation.

CSS tutorial for creating loading spinners and animations

HTML:

<div class="spinner"></div>

CSS:

CSS tutorial for creating loading spinners and animations
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #ccc;
  border-top-color: #333;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
  • The border creates the ring shape.
  • border-top-color gives the "loading" effect with a contrasting color.
  • The spin keyframe rotates the element infinitely.

This method works well for small, subtle loaders.


Custom Spinner with Multiple Dots

If you want something more visual than a rotating circle, consider animating multiple dots that appear one after another.

HTML:

<div class="dot-spinner">
  <div class="dot"></div>
  <div class="dot"></div>
  <div class="dot"></div>
</div>

CSS:

.dot-spinner {
  display: flex;
  gap: 5px;
}

.dot {
  width: 8px;
  height: 8px;
  background-color: #333;
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}

.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}
  • Each dot scales in and out at slightly different times.
  • This staggered animation gives a pulsing or bouncing effect.
  • You can change the number of dots or adjust timing for different styles.

This type of spinner is great for modern UIs where subtle motion adds personality.


Adding Animation to Buttons

Sometimes you want to show a spinner inside a button when an action is processing.

HTML:

<button class="loading-btn">
  <span class="btn-text">Submit</span>
  <span class="spinner"></span>
</button>

CSS (partial):

.loading-btn .spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid #fff;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-left: 8px;
}

.loading-btn.loading .spinner {
  display: inline-block;
}

.loading-btn.loading .btn-text {
  opacity: 0;
}
  • When the button has a loading class, the spinner appears and the text fades out.
  • You'd toggle the class using JavaScript when triggering an async action.

This approach keeps your interface responsive and gives feedback during actions like form submission.


Tips for Customization

Here are some quick tips to make your spinners work better:

  • Use semantic colors: Match the spinner color to your theme or brand.
  • Keep it small: Spinners shouldn’t dominate the screen unless necessary.
  • Consider accessibility: Add ARIA attributes if needed (aria-busy, role="status").
  • Optimize performance: Avoid overcomplicated animations that may slow down rendering.

You can mix these techniques or layer them depending on your project's needs.


That’s basically how you create and customize spinners with just CSS. It's not complicated, but getting the details right makes a difference in how smooth and professional your interface feels.

以上是CSS教程,用于創(chuàng)建加載旋轉(zhuǎn)器和動(dòng)畫(huà)的詳細(xì)內(nèi)容。更多信息請(qǐng)關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

本站聲明
本文內(nèi)容由網(wǎng)友自發(fā)貢獻(xiàn),版權(quán)歸原作者所有,本站不承擔(dān)相應(yīng)法律責(zé)任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請(qǐng)聯(lián)系admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣服圖片

Undresser.AI Undress

Undresser.AI Undress

人工智能驅(qū)動(dòng)的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用于從照片中去除衣服的在線人工智能工具。

Clothoff.io

Clothoff.io

AI脫衣機(jī)

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智能換臉工具輕松在任何視頻中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的代碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

功能強(qiáng)大的PHP集成開(kāi)發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺(jué)化網(wǎng)頁(yè)開(kāi)發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級(jí)代碼編輯軟件(SublimeText3)

熱門(mén)話題

什么是'渲染障礙CSS”? 什么是'渲染障礙CSS”? Jun 24, 2025 am 12:42 AM

CSS會(huì)阻塞頁(yè)面渲染是因?yàn)闉g覽器默認(rèn)將內(nèi)聯(lián)和外部CSS視為關(guān)鍵資源,尤其是使用引入的樣式表、頭部大量?jī)?nèi)聯(lián)CSS以及未優(yōu)化的媒體查詢樣式。1.提取關(guān)鍵CSS并內(nèi)嵌至HTML;2.延遲加載非關(guān)鍵CSS通過(guò)JavaScript;3.使用media屬性優(yōu)化加載如打印樣式;4.壓縮合并CSS減少請(qǐng)求。建議使用工具提取關(guān)鍵CSS,結(jié)合rel="preload"異步加載,合理使用media延遲加載,避免過(guò)度拆分與復(fù)雜腳本控制。

如何使用CSS在網(wǎng)站上實(shí)現(xiàn)黑模式主題? 如何使用CSS在網(wǎng)站上實(shí)現(xiàn)黑模式主題? Jun 19, 2025 am 12:51 AM

ToimplementdarkmodeinCSSeffectively,useCSSvariablesforthemecolors,detectsystempreferenceswithprefers-color-scheme,addamanualtogglebutton,andhandleimagesandbackgroundsthoughtfully.1.DefineCSSvariablesforlightanddarkthemestomanagecolorsefficiently.2.Us

您能解釋EM,REM,PX和視口單元(VH,VW)之間的區(qū)別嗎? 您能解釋EM,REM,PX和視口單元(VH,VW)之間的區(qū)別嗎? Jun 19, 2025 am 12:51 AM

The topic differencebetweenem, Rem, PX, andViewportunits (VH, VW) LiesintheirreFerencepoint: PXISFixedandbasedonpixelvalues, emissrelative EtothefontsizeFheelementoritsparent, Remisrelelatotherootfontsize, AndVH/VwarebaseDontheviewporttimensions.1.PXoffersprecis

外部與內(nèi)部CSS:最好的方法是什么? 外部與內(nèi)部CSS:最好的方法是什么? Jun 20, 2025 am 12:45 AM

thebestapphachforcssdepprodsontheproject'sspefificneeds.forlargerprojects,externalcsSissBetterDuoSmaintoMaintainability andReusability; forsMallerProjectsorsingle-pageApplications,InternaltCsmightBemoresobleable.InternalCsmightBemorese.it.it'sclucialtobalancepopryseceneceenceprodrenceprodrenceNeed

我的CSS必須在較低的情況下嗎? 我的CSS必須在較低的情況下嗎? Jun 19, 2025 am 12:29 AM

否,CSSDOESNOTHAVETOBEINLOWERCASE.CHOMENDENS,使用flowercaseisrecommondendendending:1)一致性和可讀性,2)避免使用促進(jìn)性技術(shù),3)潛在的Performent FormanceBenefits,以及4)RightCollaboraboraboraboraboraboraboraboraboraboraboraboraboraboraboraboraborationWithInteams。

內(nèi)聯(lián),塊,內(nèi)聯(lián)塊和Flex顯示值之間的關(guān)鍵區(qū)別是什么? 內(nèi)聯(lián),塊,內(nèi)聯(lián)塊和Flex顯示值之間的關(guān)鍵區(qū)別是什么? Jun 20, 2025 am 01:01 AM

在CSS中選擇正確的display值至關(guān)重要,因?yàn)樗刂圃卦诓季种械男袨椤?.inline:使元素像文本一樣流動(dòng),不獨(dú)占一行,無(wú)法直接設(shè)置寬高,適用于文本內(nèi)元素如;2.block:使元素獨(dú)占一行并占據(jù)全部寬度,可設(shè)置寬高和內(nèi)外邊距,適用于結(jié)構(gòu)化元素如;3.inline-block:兼具block特性和inline布局,可設(shè)置尺寸但仍同行顯示,適合需要一致間距的水平布局;4.flex:現(xiàn)代布局模式,適用于容器,通過(guò)justify-content、align-items等屬性輕松實(shí)現(xiàn)對(duì)齊與分布,是

什么是AutoPrefixer,它如何工作? 什么是AutoPrefixer,它如何工作? Jul 02, 2025 am 01:15 AM

Autoprefixer是一個(gè)根據(jù)目標(biāo)瀏覽器范圍自動(dòng)為CSS屬性添加廠商前綴的工具。1.它解決了手動(dòng)維護(hù)前綴易出錯(cuò)的問(wèn)題;2.通過(guò)PostCSS插件形式工作,解析CSS、分析需加前綴的屬性、依配置生成代碼;3.使用步驟包括安裝插件、設(shè)置browserslist、在構(gòu)建流程中啟用;4.注意事項(xiàng)有不手動(dòng)加前綴、保持配置更新、非所有屬性都加前綴、建議配合預(yù)處理器使用。

您如何使用CSS對(duì)SVG進(jìn)行動(dòng)畫(huà)動(dòng)畫(huà)? 您如何使用CSS對(duì)SVG進(jìn)行動(dòng)畫(huà)動(dòng)畫(huà)? Jun 30, 2025 am 02:06 AM

AnimatingSVGwithCSSispossibleusingkeyframesforbasicanimationsandtransitionsforinteractiveeffects.1.Use@keyframestodefineanimationstagesforpropertieslikescale,opacity,andcolor.2.ApplytheanimationtoSVGelementssuchas,,orviaCSSclasses.3.Forhoverorstate-b

See all articles