javascript中字體浮動(dòng)效果的簡單實(shí)例演示
在淘寶,京東等其他網(wǎng)頁上我們能夠看到,當(dāng)鼠標(biāo)移上去的時(shí)候,能夠使其下面出現(xiàn)其它選項(xiàng),現(xiàn)在就演示一下這種功能
主要是用到css里面的display,以及鼠標(biāo)觸發(fā)的事件onmouseover(),和onmouseout()方式,在加上css樣式的設(shè)置和標(biāo)簽之間額使用就能實(shí)現(xiàn)。
具體如下:
1,為了很好的控制,采用了列表的樣式,并且在設(shè)置css樣式時(shí)很方便
2,采用了<a>標(biāo)簽的樣式,能夠讓鼠標(biāo)移上去對(duì)其他的有反應(yīng)
具體的js函數(shù)寫的功能:
<script type="text/javascript"> function open1(node){ var node1=node; var nodes=node1.getElementsByTagName("ul")[0]; with(nodes.style){ display= (display=="block")? "none" : "block"; } } </script>
html部分的代碼:
<div id="news"> <ul id="newsid1"> <li onmouseover="open1(this)"; onmouseout="open1(this)"> <!--<a href="javascript:void(0)" onmouseover="open1(this)"; onmouseout="open1(this)" >最新新聞</a> 在這里,移動(dòng)第一個(gè)之后就會(huì)消失,不能夠點(diǎn)擊下面的--> <a href="javascript:void(0)">最新新聞</a> <ul><!--這樣包裝為了能更好的封裝下面的內(nèi)容,到時(shí)候鼠標(biāo)移動(dòng)上面,就能對(duì)下面的這個(gè)操作了--> <li><a >最新新聞內(nèi)容摘要《機(jī)密》1</a></li> <li><a >最新新聞內(nèi)容摘要《機(jī)密》2</a></li> <li><a >最新新聞內(nèi)容摘要《機(jī)密》3</a></li> <li><a >最新新聞內(nèi)容摘要《機(jī)密》4</a></li> <li><a >最新新聞內(nèi)容摘要《機(jī)密》5</a></li> </ul> </li> <li onmouseover="open1(this)"; onmouseout="open1(this)"> <a href="javascript:void(0)" onclick="">新浪新聞</a> <ul> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》1</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》2</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》3</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》4</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》5</a></li> </ul> </li> <li onmouseover="open1(this)"; onmouseout="open1(this)"> <a href="javascript:void(0)" onclick="">社會(huì)新聞</a> <ul> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》1</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》2</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》3</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》4</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》5</a></li> </ul> </li> <li onmouseover="open1(this)"; onmouseout="open1(this)"> <a href="javascript:void(0)" onclick="">最新新聞</a> <ul> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》1</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》2</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》3</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》4</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》5</a></li> </ul> </li></ul></div>
除了上面很重要css的設(shè)置也很重要,如下:
<style type="text/css"> #newsid1 { list-style:none; } #newsid1 li ul{ list-style:none; margin:0px; padding:0px; } #newsid1 li{ float:left;/*讓其并排顯示*/ width:220px; text-align:center; background-color:#80ff00; /*設(shè)置寬度,讓每一列平均顯示*/ } #newsid1 li a{ color:#8080ff; text-decoration:none;/*讓超鏈接下面沒有橫線*/ text-align:center; line-height:30px; } #newsid1 li a:hover{ /*a:hover移上去有反應(yīng)設(shè)置的具體的顏色和背景顏色 */ color:#400080; background-color:#ffffff; } #newsid1 li ul li{ line-height:30px; color:#ff8040; background-color:#808000;; } #newsid1 li ul{ display:none;/*默認(rèn)的必須全部隱藏,然后在鼠標(biāo)移上去觸發(fā)時(shí)間之后設(shè)置 dispaly:block; */ } </style>
效果圖 1:鼠標(biāo)沒有移上去時(shí)候
效果圖 2 :
完整代碼:
<!DOCTYPE html> <html> <head> <!--主要目的 當(dāng)鼠標(biāo)滑過文字時(shí)候出現(xiàn)其他文字顯示 采用<ul>和<li><a href="標(biāo)題"><ul><li>隱藏的內(nèi)容 采用大量的css模型進(jìn)行修飾 傳入this對(duì)象 function open1(node){ var node1=node; var nodes=node1.getElementsByTagName("ul")[0]; with(nodes.style){ display= (display=="block")? "none" : "block"; } } --> <title>Menufloat.html</title> <style type="text/css"> #newsid1 { list-style:none; } #newsid1 li ul{ list-style:none; margin:0px; padding:0px; } #newsid1 li{ float:left;/*讓其并排顯示*/ width:220px; text-align:center; background-color:#80ff00; /*設(shè)置寬度,讓每一列平均顯示*/ } #newsid1 li a{ color:#8080ff; text-decoration:none;/*讓超鏈接下面沒有橫線*/ text-align:center; line-height:30px; } #newsid1 li a:hover{ /*a:hover移上去有反應(yīng)設(shè)置的具體的顏色和背景顏色 */ color:#400080; background-color:#ffffff; } #newsid1 li ul li{ line-height:30px; color:#ff8040; background-color:#808000;; } #newsid1 li ul{ display:none;/*默認(rèn)的必須全部隱藏,然后在鼠標(biāo)移上去觸發(fā)時(shí)間之后設(shè)置 dispaly:block; */ } </style> <script type="text/javascript"> function open1(node){ var node1=node; var nodes=node1.getElementsByTagName("ul")[0]; with(nodes.style){ display= (display=="block")? "none" : "block"; } } </script> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> </head> <body> <div id="news"> <ul id="newsid1"> <li onmouseover="open1(this)"; onmouseout="open1(this)"> <!--<a href="javascript:void(0)" onmouseover="open1(this)"; onmouseout="open1(this)" >最新新聞</a> 在這里,移動(dòng)第一個(gè)之后就會(huì)消失,不能夠點(diǎn)擊下面的--> <a href="javascript:void(0)">最新新聞</a> <ul><!--這樣包裝為了能更好的封裝下面的內(nèi)容,到時(shí)候鼠標(biāo)移動(dòng)上面,就能對(duì)下面的這個(gè)操作了--> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》1</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》2</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》3</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》4</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》5</a></li> </ul> </li> <li onmouseover="open1(this)"; onmouseout="open1(this)"> <a href="javascript:void(0)" onclick="">新浪新聞</a> <ul> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》1</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》2</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》3</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》4</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》5</a></li> </ul> </li> <li onmouseover="open1(this)"; onmouseout="open1(this)"> <a href="javascript:void(0)" onclick="">社會(huì)新聞</a> <ul> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》1</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》2</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》3</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》4</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》5</a></li> </ul> </li> <li onmouseover="open1(this)"; onmouseout="open1(this)"> <a href="javascript:void(0)" onclick="">最新新聞</a> <ul> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》1</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》2</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》3</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》4</a></li> <li><a href="http://www.dbjr.com.cn">最新新聞內(nèi)容摘要《機(jī)密》5</a></li> </ul> </li> </ul> </div> </body> </html>
- js浮動(dòng)圖片的動(dòng)態(tài)效果
- js 圖片隨機(jī)不定向浮動(dòng)的實(shí)現(xiàn)代碼
- 基于javascript實(shí)現(xiàn)右下角浮動(dòng)廣告效果
- js 右側(cè)浮動(dòng)層效果實(shí)現(xiàn)代碼(跟隨滾動(dòng))
- JavaScript實(shí)現(xiàn)上下浮動(dòng)的窗口效果代碼
- js實(shí)現(xiàn)浮動(dòng)在網(wǎng)頁右側(cè)的簡潔QQ在線客服代碼
- JS實(shí)現(xiàn)彈出浮動(dòng)窗口(支持鼠標(biāo)拖動(dòng)和關(guān)閉)實(shí)例詳解
- JS實(shí)現(xiàn)可縮放、拖動(dòng)、關(guān)閉和最小化的浮動(dòng)窗口完整實(shí)例
- javascript實(shí)現(xiàn)div浮動(dòng)在網(wǎng)頁最頂上并帶關(guān)閉按鈕效果實(shí)例
- js實(shí)現(xiàn)的簡單圖片浮動(dòng)效果完整實(shí)例
相關(guān)文章
請(qǐng)求時(shí)token過期自動(dòng)刷新token操作
這篇文章主要介紹了請(qǐng)求時(shí)token過期自動(dòng)刷新token操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-09-09js控制文本框只能輸入中文、英文、數(shù)字與指定特殊符號(hào)的實(shí)現(xiàn)代碼
下面小編就為大家?guī)硪黄猨s控制文本框只能輸入中文、英文、數(shù)字與指定特殊符號(hào)的實(shí)現(xiàn)代碼。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-09-09JS高級(jí)調(diào)試技巧:捕獲和分析 JavaScript Error詳解
前端工程師都知道 JavaScript 有基本的異常處理能力。我們可以 throw new Error(),瀏覽器也會(huì)在我們調(diào)用 API 出錯(cuò)時(shí)拋出異常。但估計(jì)絕大多數(shù)前端工程師都沒考慮過收集這些異常信息2014-03-03JS中BOM相關(guān)知識(shí)點(diǎn)總結(jié)(必看篇)
下面小編就為大家?guī)硪黄狫S中BOM相關(guān)知識(shí)點(diǎn)總結(jié)(必看篇)。小編覺得挺不錯(cuò)的,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧,祝大家游戲愉快哦2016-11-11Bootstrap優(yōu)化站點(diǎn)資源、響應(yīng)式圖片、傳送帶使用詳解3
這篇文章主要介紹了Bootstrap優(yōu)化站點(diǎn)資源、完成響應(yīng)式圖片、讓傳送帶支持手勢(shì)的相關(guān)知識(shí),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10layer.open回調(diào)獲取彈出層參數(shù)的實(shí)現(xiàn)方法
今天小編就為大家分享一篇layer.open回調(diào)獲取彈出層參數(shù)的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-09-09