純css實現(xiàn)Magicline Navigation(下劃線動畫導(dǎo)航菜單)_html/css_WEB-ITnose
Jun 24, 2016 am 11:45 AM
看別人網(wǎng)站的時候,看到一種導(dǎo)航菜單的動畫,覺得很有意思,就仔細(xì)研究起來。
目前見過的動畫有三種:水平下劃線動畫導(dǎo)航、水平背景動畫導(dǎo)航、垂直動畫導(dǎo)航,他們實現(xiàn)思路都是一樣的,都是依賴 css3的同級通用選擇器 "~" 。
自己實現(xiàn)了一遍,本文簡要記錄實現(xiàn)的思想。
大家可以先看看最后實現(xiàn)的效果:Demo點我
實現(xiàn)思路
HTML 結(jié)構(gòu)
HTML結(jié)構(gòu)沒有特殊,就是 ul -> li:
<ul class="a"> <li class="n1"><a href="#">Navigator A</a></li> <li class="n2"><a href="#">Navigator B</a></li> <li class="n3 selected"><a href="#">Navigator C</a></li> <li class="n4"><a href="#">Navigator D</a></li> <li class="quebec"> </li></ul>
最后一個li空著,留著后面有用。
CSS 布局
實現(xiàn)基本樣式,不多解釋:
li { list-style: none outside; position: relative; z-index: 1; float: left; padding: 0 0 0 0; } li a { position: relative; top: 5px; display: block; margin: 0 0; border-bottom: 5px solid transparent; padding: 10px 0; text-align: center; text-decoration: none; } .selected a { border-bottom: 5px solid #cfd0d0; color: #340e56; }
實現(xiàn)導(dǎo)航下劃線
下面實現(xiàn)動畫部分。
下方紫色滾動條是通過,剛才留著的最后一個li元素實現(xiàn)。
.quebec { position: absolute; bottom: -5px; left: 0; z-index: 3; margin: 0; border: 0; width: 5px; height: 5px; padding: 0; overflow: hidden; text-indent: -9999em; background: #511d7f; -webkit-transition-property: left, width; -moz-transition-property: left, width; -ms-transition-property: left, width; -o-transition-property: left, width; transition-property: left, width; -webkit-transition-duration: .5s; -moz-transition-duration: .5s; -ms-transition-duration: .5s; -o-transition-duration: .5s; transition-duration: .5s; }
通過絕對定位,把最后一個 li.quebec 定位到導(dǎo)航下方,設(shè)置寬度高度。設(shè)置 transition,當(dāng)我們改變 left, width的時候就能實現(xiàn)動畫。
動起來
當(dāng)hover到導(dǎo)航上面的時候,li.quebec 就定位left到其下面。實現(xiàn)這個效果的是css3的同級通用選擇器 “~”
比如 A ~ B 匹配的是 任何在A元素之后的同級B元素。
.n1:hover ~ li.quebec { left: 0; width: 95px; } .n2:hover ~ li.quebec { left: 100px; width: 95px; } .n3:hover ~ li.quebec { left: 192px; width: 95px; } .n4:hover ~ li.quebec { left: 285px; width: 95px; }
這里就完成了一個 純css的下劃線動畫導(dǎo)航。 最后的效果:Demo查看
擴展
當(dāng)我們會實現(xiàn)水平的下劃線動畫導(dǎo)航后,實現(xiàn) 背景移動動畫導(dǎo)航 思路也是一樣,不過是li.quebec高度寬度的變化,背景透明度的變化。
垂直的動畫導(dǎo)航 亦是如此,改變 li.quebec 的高度寬度,通過 translateY 控制其在垂直方向的位置。
為了效果更炫一點,我們還可以在hover不同li的時候,改變li.quebec的顏色、背景、透明度等。

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

HTML?? ??? ??? ????? ???? ??? ?? ???, ??? ? SEO ??? ?? ? ? ????. 1. ??? ????? ??? ?? ??? ? ??? ??? ????? ?? ????????. 2. ????? ??? ???? ?? ?? ???? ???? ???? ?? ??? ?????. 3. ? ???? ??? ?? ??? ????? ??? ? ?? ?? ?? ?? ????? ?? ??? ????. ?? ???? ??? ??????? ?? ??? ??? ??? ???? ???? ??? ??? ?? ??? ???? ???????.

?? = "Lazy"? HTML ???? ????? ?? ????? ??? ??? ??? ???? ? ????. 1. ??? ??? ?????? ?????, ?? ?? ??? ???, ??? ? ?? ??? ?????. 2. ? ???? ?? ?? ?? ?? ???? ???? ?????. 3. JavaScript? ???? ? ?? ?? ???, ?? ??? ?? ??? ??? ???? ????. 4. ???? ???? ??? ???? ???? ?? ?? ?? ? ?? ??? ?? ??? ??? ???????. ??? ??? ?? ??? ??? ????? ??? ??? ???????.

????? ??? HTML? ??? ?? ??? ??, ??? ?? ? ??? ? ?????? ???????. 1. ??? ?? ?? ??? ???? ????? HTML5 ??? ?? ?? ????? ??????. 2. ???? ??? ?? ??? ?? ??? ??? ?? ????? ??????. 3. ??? ? SEO? ?? ??? ?? ?? ??????. 4. ?? ?? ?? ???? ???? ?? ?? ?? ???? ???? ?????. ?? ??? ???? ??????. ??? ??? ??? ????? ?? ??? ??????.

? ??? ??? Core HTML ???? ???????. 1. ???? ?? ??? ?? ??? ???? ??? ???? ?? ?? ? ?? ??? ?????. 2. ??? ??? ?? ?? ? SEO? ???? ?? ?? (-), ?? () ? ?? ?? (? :)? ?????. 3. ?????? ???? ????, ????? ???? ??? ???? ????? ?? Aria-Current ??? ???? ?????. 4. ?? ?? ???? ?? ??? ?? ? ?? ??? ?????. ??? ??? ???? ???? ??? ???, ?? ?? ? ?? ?? ???? ?? ? ? ????.

??? HTML? ??? ??? ???? ??? ???? ???? ?? ?? ?????. ??? = "..."? ??? ?? ? ?? CSS ??? ??????. 1. ?? ?? ??? ??? ??? ?? ?? ?? CSS ??????. ? ???? ?????? ?????. ??? ?? ?? : ?? ????. ?? ?? :? ??? ??? ??????. ?? ??? ???? ?? ????? ???????. ? CSS ???? ????? ????????. ?? ??? CSS? ?? ?? ?????. 2. ??? ???? ?? ??? ?????? ?? ??? ???, ??? ??? ?? ? ?? ???? ?????. 3. ????? ? ?? ???? ?? ??? ??? ???? ???, ?? ?? ?? ? ?? ??? ?????.

JavaScript? DOM ??? ?? HTML ??? ???? ??, ??, ?? ? ?????. 1. document.creeLement ()? ???? ? ??? ???? accendChild () ?? insertbefore ()? ?? ???? ??????. 2. QuerySelector () ?? getElementByid ()? ?? ?? ??? ???? TextContent, InnerHtml, setAttribute () ? ?? ???? ???? ?????. 3. ??? ?? ?? ??? ?? ? ? QuerySelectorAll ()? NODELIST? ?????. 4. ??

Thefour Mostimpactfulhtmlattributesforseoarethetitletag, altattribute, hrefattribute, and metadescription.1.theTitleTaginSectionIscrucialasItinformsUsersandsearchEnspage 'scoundents, ??, ???-event, and60 Characters

TheintegrityAttributeNsuresAresouresourcehas? notbeenmodified becryryptographichash, whilecrossoriginhandlescross-originrequeststoenablepropervalidation.1.integritychecksthefile'sauthenticityviasha-256, sha-384, orsha-512HASHASHES, BLOCKINICONCERCOTED
