嗨即時嘗試讓我的導航欄做鼠標懸停的CSS焦點效果,所以它不會改變,直到另一個菜單項有鼠標懸停。我試圖用JQuery來做。更改鼠標上的css類
這裏是我的代碼(我做了順便說一句,我的CSS類導入jQuery腳本):
<div id="topNav">
<a href="contact.html"class="topNavNormal"><div id="topNav4" class="topNavNormal">Contact Us</div></a>
<a href="about.html" class="topNavNormal"><div id="topNav3" class="topNavNormal">About Us</div></a>
<a href="services.html" class="topNavNormal"><div id="topNav2" class="topNavNormal">Services</div></a>
<a href="index.html" class="topNavActive"><div id="topNav1" class="topNavActive" style="border-left: 3px solid #c0c0c0;">Home</div></a>
<script type="text/javascript">
$(document).ready(function(){
$('#topNav1').mouseover(function(){
$('#topNav1').removeClass().addClass('topNavActive'),
$('#topNav2').removeClass().addClass('topNavNormal'),
$('#topNav3').removeClass().addClass('topNavNormal'),
$('#topNav4').removeClass().addClass('topNavNormal'),
});
}),
$('#topNav2').mouseover(function(){
$('#topNav2').removeClass().addClass('topNavActive'),
$('#topNav1').removeClass().addClass('topNavNormal'),
$('#topNav3').removeClass().addClass('topNavNormal'),
$('#topNav4').removeClass().addClass('topNavNormal'),
});
}),
$('#topNav3').mouseover(function(){
$('#topNav3').removeClass().addClass('topNavActive'),
$('#topNav1').removeClass().addClass('topNavNormal'),
$('#topNav2').removeClass().addClass('topNavNormal'),
$('#topNav4').removeClass().addClass('topNavNormal'),
});
}),
$('#topNav4').mouseover(function(){
$('#topNav4').removeClass().addClass('topNavActive'),
$('#topNav1').removeClass().addClass('topNavNormal'),
$('#topNav3').removeClass().addClass('topNavNormal'),
$('#topNav2').removeClass().addClass('topNavNormal'),
});
});
</script>
</div>
而且這裏是我的CSS類:
<style type="text/css">
#topNav1
{
text-align: center;
font-size: 18px;
float: right;
width: 50px;
height: 64px;
}
#topNav2
{
text-align: center;
font-size: 18px;
float: right;
width: 70px;
height: 64px;
}
#topNav3
{
text-align: center;
font-size: 18px;
float: right;
width: 90px;
height: 64px;
}
#topNav4
{
text-align: center;
font-size: 18px;
float: right;
width: 90px;
height: 64px;
}
#topNav1, #topNav2, #topNav3{
border-right: 1px solid #c0c0c0;
}
#topNav4{
border-right: 3px solid #c0c0c0;
}
a .topNavNormal{
line-height: 54px;
color: #42647F;
}
.topNavNormal{
background-color: #B0E0E6;
}
a .topNavActive{
line-height: 54px;
color: #00EEEE;
background-color: #5F9EA0;
}
</style>
如果你不打算擔心ie6使用CSS選擇器':hover' http://www.htmldog.com/guides/cssintermediate/pseudoclasses/ –
我試着檢查CSS選擇器,但沒有我看到將專注於鼠標懸停(有一個懸停,但它一旦你的鼠標關閉它取消,但我只希望它在其他菜單項被突出顯示時取消)。另外我不能讓用戶點擊以專注,因爲點擊會進入新的頁面。 – Matthew
啊,我沒有完全站立,但現在我相信你的意思是最後一個懸停的項目將是這個「積極」類 –