我的問題是類似這樣的:How can you make CSS on-hover content stay in place when you click or stop hovering using Javascript?使圖像停留在CSS-懸停內容,當你點擊它
然而,我沒有很好地理解,提出瞭解決方案。
所以基本上,我希望我的CSS懸停內容留在我的圖片上,當用戶點擊它。有人能告訴我該怎麼做嗎?
#core {
max-width: 960px;
margin-top: 25px;
}
ul.img-list {
list-style-type: none;
margin: 0;
padding: 0;
text-align: center;
}
ul.img-list li {
display: inline-block;
height: 120px;
margin: 0 1em 1em 0;
position: relative;
width: 120px;
}
span.background-content span {
display: table-cell;
text-align: center;
vertical-align: middle;
}
ul.img-list li:hover span.background-content {
opacity: 1;
}
span.background-content {
background: rgba(0, 0, 0, 0.5);
color: white;
cursor: pointer;
display: table;
height: 120px;
left: 0;
position: absolute;
top: 0;
width: 120px;
opacity: 0;
-webkit-transition: opacity 500ms;
-moz-transition: opacity 500ms;
-o-transition: opacity 500ms;
transition: opacity 500ms;
}
/* --------------------------------------------------------- */
span.title-content-platinum {
background: rgba(215, 215, 0, 0.8);
color: white;
cursor: pointer;
display: table;
height: 20px;
left: 0;
position: absolute;
top: -20px;
width: 120px;
}
span.title-content-platinum span {
display: table-cell;
text-align: center;
vertical-align: middle;
}
span.title-content-platinum {
background: rgba(215, 215, 0, 0.8);
color: white;
cursor: pointer;
display: table;
height: 20px;
left: 0;
position: absolute;
top: -20px;
width: 120px;
opacity: 0;
}
ul.img-list li:hover span.title-content-platinum {
opacity: 1;
}
span.title-content-platinum {
background: rgba(215, 215, 0, 0.8);
color: white;
cursor: pointer;
display: table;
height: 20px;
left: 0;
position: absolute;
top: -20px;
width: 120px;
opacity: 0;
-webkit-transition: opacity 500ms;
-moz-transition: opacity 500ms;
-o-transition: opacity 500ms;
transition: opacity 500ms;
}
<div id="core">
<ul class="img-list">
<li>
<a>
<a href="">
<img src="http://www.pokepedia.fr/images/thumb/e/e7/Pikachu-RFVF.png/120px-Pikachu-RFVF.png" alt="" width="120" height="120" />
</a>
<span class="title-content-platinum">Pikachu</span>
<span class="background-content"><span></span></span>
</a>
</li>
</ul>
</div>
我也在學習JavaScript(不jQuery的的時刻),所以涉及的JScript的解決方案,將不勝感激!
你的意思是,一旦你懸停,你想要的跨度覆蓋住可見,即使你的時候unhover? – showdev 2014-10-02 18:07:09
我希望跨度覆蓋保持可見的onclick並保持這種方式,直到我再次點擊圖像。 – Macjeje 2014-10-02 18:11:05