简体   繁体   English

划分图像和鼠标悬停事件

[英]Div over image and mouseover event

I have a site with images and some of them have a "play" (a div positioned absolutely and managed via click event on jQuery) over it. 我有一个带有图像的网站,其中一些有一个“游戏”(一个div绝对定位,并通过jQuery上的点击事件管理)。

In some images I must to change the opacity when the mouse is over the image. 在某些图像中,我必须在鼠标悬停在图像上时更改不透明度。

When an imagen have at same time the "play" and the opacity change, this is happening (place the mouse over the "play" div): http://jsfiddle.net/S53b5/ 当图像同时具有“播放”和不透明度变化时,会发生这种情况(将鼠标放在“播放”div上): http//jsfiddle.net/S53b5/

I have tried different solutions only CSS or using jQuery, but anything works :( 我尝试过不同的解决方案只有CSS或使用jQuery,但任何工作:(

Thanks! 谢谢!

try this demo 试试这个演示

   $("img").mouseout(function(){
     $(".play").css("opacity","1")
    }).mouseover(function(){
     $(".play").css("opacity",".5");
    });

Updated Demo2 更新了演示2

$("img").mouseout(function(){
        $(".play").css("opacity","1");
         $(this).css("opacity",".1");
    }).mouseover(function(){
        $(".play").css("opacity",".5");
        $(this).css("opacity","1");
    });

$(".play").mouseover(function(){
        $(this).css("opacity","1");
        $("img").css("opacity","1");
    });
$("img").mouseover(function(){
    $(this).css("opacity",".8");
})
$("#(yourimageid)").mouseover(function(){
$(this).css("opacity","0.7")
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM