我有一個懸停功能,可以將文字懸停在圖像下。但是我希望文字覆蓋在圖像上。因此,我們將鼠標懸停在圖像上會淡出一點,文本將顯示。CSS/jQuery - 懸停時圖像上的文字
像這樣:
任何人都可以幫我嗎?
這裏是jQuery的:
<%def name="javascript()">
<script type="text/javascript">
$(document).ready(function() {
$('.category-box').each(function() {
var hovertext = $(this).find('.hovertext').html();
var hoverbox = $('<div id="hoverbox">' + hovertext + '</div>').css({
'position': 'absolute',
'top': $(this).css('top'),
'left': $(this).css('left'),
'width': $(this).css('width'),
'background-color': '#f0f0f0',
'z-index': 1000,
'border-radius': '5px',
'-moz-border-radius': '5px',
'-webkit-border-radius': '5px',
'display': 'none',
'cursor': 'pointer'
});
$(this).find('h4').after(hoverbox);
$(this).hover(function() {
hoverbox.fadeIn('fast');
}, function() {
hoverbox.fadeOut('fast');
});
$(this).not('#mitp').click(function() {
location.href = '${request.route_url('
new_case ', category='
')}' + $(this).find('h4').html();
});
});
$('#mitp').click(function() {
location.href = '${request.route_url('
mitp ')}';
});
});
尖吻鯖鯊:
% if categories:
% for category in categories:
<div class="category-box">
<img src="/category_icon/${category['id']}" width="120" height="120" />
<h4>${category['name']}</h4>
<span class="hovertext">
% if category['description'] != '.':
${h.literal(category['description'])}
% endif
</span>
</div>
% endfor
% endif
而CSS:
.category-box {
float: left;
margin: 15px 10px 5px 10px;
text-align: center;
width: 120px;
min-height: 120px;
cursor: pointer;
}
.category-box:hover {
cursor: pointer;
background-color: #f0f0f0;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
}
.hovertext {
text-align: center;
display: none;
}
你能提供的jsfiddle? – AndrewLeonardi
'.category-box:hover {opacity:.3}'應該可以做到。 – Roberrrt