2

如何在 img 元素悬停时设置 z-index?当鼠标指针在 img 之外时,z-index 必须为 0,否则应为 9。

我确实知道如何设置它,但不知道如何在悬停时更改它。

$('#content img').click(function () {
    $(this).css("z-index", "99")
});
4

3 回答 3

9
$('#content img').mouseover(function () {
    $(this).css("z-index", "9")
});

$('#content img').mouseout(function () {
    $(this).css("z-index", "0")
});
于 2012-10-08T06:36:12.307 回答
4

仅使用 css 的解决方案:

 #content img{
   z-index:0;
 }

 #content img:hover{
   z-index:9;
 }
于 2012-10-08T06:54:44.843 回答
2

试试这个

$('#content img').hover( 
   function() { 
     $(this).css("z-index", "99")
   },
   function() { 
     $(this).css("z-index", "0")
   });
于 2012-10-08T07:35:28.983 回答