【发布时间】:2014-03-09 19:51:10
【问题描述】:
由于 Cargocollective 的运行方式,我以一种奇怪的方式创建了导航。 As you can see 侧面有一个导航,点击后会滚动到一个锚点,每个点代表一个锚点。我想要做的是拥有它,所以当我点击其中一个点时,它会保持颜色,直到我点击另一个。就像a:active 的行为一样
a:active{color:green;} 不工作。
这就是我所做的:
正如您所见,当您单击链接时,它会变为绿色,但它不会像您期望的活动链接那样保持绿色。
HTML
<div id="navigation">
<a href="#i">•</a><br>
<a href="#ii">•</a><br>
<a href="#iii">•</a><br>
<a href="#iv">•</a><br>
<a href="#v">•</a><br>
<a href="#vi">•</a><br>
<a href="#vii">•</a><br>
<a href="#viii">•</a><br>
<a href="#ix">•</a><br>
<a href="#x">•</a><br>
<a href="#xi">•</a><br>
<a href="#xii">•</a><br>
<a href="#xiii">•</a><br>
</div>
CSS
#navigation {
position: fixed;
top: 50%;
margin-top: -140px;
right: 10px;
z-index: 1000;
text-align: center;
width: 180px;
font-size: 20px;
z-index: 9999;
}
#navigation a:link {
color: #aaa;
text-decoration: none;
}
#navigation a:hover {
color: #000;
}
#navigation a:active {
color: green;
}
JQUERY
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^//,'') == this.pathname.replace(/^//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
【问题讨论】:
-
:active表示(或多或少)“在被点击时”