JS實現(xiàn)css hover操作的方法示例
本文實例講述了JS實現(xiàn)css hover操作的方法。分享給大家供大家參考,具體如下:
hover我們可以用css的方式寫,當(dāng)然,也可以用js的方式寫
<html>
<head>
<title>js的下拉菜單效果</title>
<style type="text/css">
*{
padding:0px;
margin:0px;
}
ul li{
list-style: none;
}
a{
text-decoration: none
}
.header{
height: 45px;
background-color:#FBFBFB;
border-bottom: 1px solid #C7C7C7;
}
.header-center{
width: 1000px;
height: 100%;
margin: 0 auto;
position: relative;
}
.header-mobile{
width: 130px;
position: absolute;
top:0;
right: 0;
text-align: center;
}
/* .header-mobile:hover .header-mobile-list{
display: block;
}*/
.header-mobile a{
display: block;
height: 45px;
line-height: 45px;
color:#000000;
}
.header-mobile-list{
display: none;
background:url(bg.png) no-repeat;
background-position: 20px 18px;
}
.header-mobile-list li{
height: 45px;
border-bottom: 1px dashed gray;
font-family: '微軟雅黑';
line-height: 50px;
padding-left: 35px;
padding-top: 5px;
}
</style>
</head>
<body>
<header class="header">
<div class="header-center">
<div class="header-mobile" id="headerMobile">
<a href="">移動客戶端</a>
<ul class="header-mobile-list" id="mobileList">
<li>新浪微博</li>
<li>新浪新聞</li>
<li>新浪體育</li>
<li>新浪娛樂</li>
<li>新浪財經(jīng)</li>
<li>天氣通</li>
</ul>
</div>
</div>
</header>
</body>
<script type="text/javascript">
//封裝選擇ID
window.onload=function(){
function $(id){
return document.getElementById(id);
}
//鼠標(biāo)進(jìn)
$("headerMobile").onmouseover=function(){
// this.style.display="none";
$("mobileList").style.display="block"
//給當(dāng)錢的添加樣式
this.style.boxShadow=" 0 2px 2px gray"
}
//鼠標(biāo)出
$("headerMobile").onmouseout=function(){
$("mobileList").style.display="none"
this.style.boxShadow='none'
}
}
</script>
</html>
運行效果圖如下:

更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript事件相關(guān)操作與技巧大全》、《JavaScript頁面元素操作技巧總結(jié)》、《JavaScript操作DOM技巧總結(jié)》、《JavaScript錯誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運算用法總結(jié)》
希望本文所述對大家JavaScript程序設(shè)計有所幫助。
相關(guān)文章
以JavaScript來實現(xiàn)WordPress中的二級導(dǎo)航菜單的方法
這篇文章主要介紹了以JavaScript來實現(xiàn)WordPress中的二級導(dǎo)航菜單的方法,文中首先對WordPress基本的PHP導(dǎo)航菜單的做法給出了說明來作為基礎(chǔ),需要的朋友可以參考下2015-12-12
PHP實現(xiàn)的各種中文編碼轉(zhuǎn)換類分享
這篇文章主要介紹了PHP實現(xiàn)的各種中文編碼轉(zhuǎn)換類分享,本文類庫支持簡體中文、繁體中文、GB2312、BIG5、UTF-8等多種格式之間的轉(zhuǎn)換,需要的朋友可以參考下2015-01-01
JavaScript中使用Object.prototype.toString判斷是否為數(shù)組
這篇文章主要介紹了JavaScript中使用Object.prototype.toString判斷是否是數(shù)組,本文講解了Object.prototype.toString相關(guān)知識,并給出了判斷數(shù)組的實現(xiàn)代碼,使用本文方法同樣可以判斷javascrpty的其它數(shù)據(jù)類型,需要的朋友可以參考下2015-04-04

