因为导航的颜色在特定图片上难以辨认,所以我希望它针对特定页面进行更改。这是HTML:
<div id='nav'>
<ul>
<li id='navBiog'><a href="javascript:void(0)" onclick="imageChange(1, 400)" class="navItem">biography</a></li>
<li id='navConductor'><a href="javascript:void(0)" onclick="imageChange(2, 400)" class="navItem">conductor</a></li>
<li id='navOrchestrator'><a href="javascript:void(0)" onclick="imageChange(3, 400)" class="navItem">orchestrator</a></li>
<li id='navGallery'><a href="javascript:void(0)" onclick="imageChange(4, 400)" class="navItem">gallery</a></li>
<li id='navContact'><a href="javascript:void(0)" onclick="imageChange(5, 400)" class="navItem">contact</a></li>
</ul>
</div>
CSS
a.navItem:link,a.navItem:visited{
font-family:"Helvetica", "Arial", sans-serif;
font-size:20px;
text-align:right;
padding:4px 6px 4px 6px;
text-decoration:none;
color:#333;
transition:color 1s;
-moz-transition:color 1s; /* Firefox 4 */
-webkit-transition:color 1s; /* Safari and Chrome */
-o-transition:color 1s; /* Opera */
}
#navBiog a.navItem:hover,a:active {color:#cc0099;}
#navConductor a.navItem:hover,a:active {color:#ff9900;}
#navOrchestrator a.navItem:hover,a:active {color:#66cc66;}
#navGallery a.navItem:hover,a.navItem:active {color:#6699ff;}
#navContact a.navItem:hover,a.navItem:active {color:#FF0;}
和 jQuery
switch (i)
{
case 0:
$('.content').fadeOut(500);
$('a.navItem:link').animate({color: "#333"});
$('#navBiog a.navItem:hover,a:active',
'#navConductor a.navItem:hover,a:active',
'#navOrchestrator a.navItem:hover,a:active',
'#navGallery a.navItem:hover,a:active',
'#navContact a.navItem:hover,a:active').css({'color': ''});
break;
case 1:
$('.content').slideUp(700);
$('#biogContent').slideDown(700, function(){
$('h1').animate({color: "#cc0099"});
$('a.navItem:link').animate({color: "#333"});
$('#navBiog a.navItem:hover,a:active',
'#navConductor a.navItem:hover,a:active',
'#navOrchestrator a.navItem:hover,a:active',
'#navGallery a.navItem:hover,a:active',
'#navContact a.navItem:hover,a:active').css({'color': ''});
});
break;
case 2:
$('.content').slideUp(700);
$('#condContent').slideDown(700, function(){
$('h1').animate({color: "#ff9900"});
$('a.navItem:link').animate({color: "#333"});
$('#navBiog a.navItem:hover,a:active',
'#navConductor a.navItem:hover,a:active',
'#navOrchestrator a.navItem:hover,a:active',
'#navGallery a.navItem:hover,a:active',
'#navContact a.navItem:hover,a:active').css({'color': ''});
});
break;
case 3:
$('.content').slideUp(700);
$('#orchContent').slideDown(700, function(){
$('h1').animate({color: "#66cc66"});
$('a.navItem:link').animate({color: "#ffffff"});
$('#navBiog a.navItem:hover,a:active',
'#navConductor a.navItem:hover,a:active',
'#navOrchestrator a.navItem:hover,a:active',
'#navGallery a.navItem:hover,a:active',
'#navContact a.navItem:hover,a:active').css({'color': ''});
});
break;
case 4:
$('.content').slideUp(700);
$('#mediaContent').slideDown(700, function(){
$('h1').animate({color: "#6699ff"});
$('a.navItem:link').animate({color: "#333"});
$('#navBiog a.navItem:hover,a:active',
'#navConductor a.navItem:hover,a:active',
'#navOrchestrator a.navItem:hover,a:active',
'#navGallery a.navItem:hover,a:active',
'#navContact a.navItem:hover,a:active').css({'color': ''});
});
break;
case 5:
$('.content').slideUp(700);
$('#contactContent').slideDown(700, function(){
$('h1').animate({color: "#ff0"});
$('a.navItem:link').animate({color: "#333"});
$('#navBiog a.navItem:hover,a:active',
'#navConductor a.navItem:hover,a:active',
'#navOrchestrator a.navItem:hover,a:active',
'#navGallery a.navItem:hover,a:active',
'#navContact a.navItem:hover,a:active').css({'color': ''});
});
break;
default:
break;
}
很抱歉有大量的代码,但很难用语言表达。无论如何,初始颜色更改有效,但悬停不起作用 - 显然这很复杂,因为导航中的每个链接在悬停时都是不同的颜色......
非常感谢您,如果这是一个非常愚蠢的问题/被问了一千次但我找不到它,我们深表歉意。