如何在 img 元素悬停时设置 z-index?当鼠标指针在 img 之外时,z-index 必须为 0,否则应为 9。
我确实知道如何设置它,但不知道如何在悬停时更改它。
$('#content img').click(function () {
$(this).css("z-index", "99")
});
$('#content img').mouseover(function () {
$(this).css("z-index", "9")
});
$('#content img').mouseout(function () {
$(this).css("z-index", "0")
});
仅使用 css 的解决方案:
#content img{
z-index:0;
}
#content img:hover{
z-index:9;
}
试试这个
$('#content img').hover(
function() {
$(this).css("z-index", "99")
},
function() {
$(this).css("z-index", "0")
});