简体   繁体   English

悬停在图像上时如何使背景变暗

[英]How to darken background when hovering on image

I have created a jQuery hover button. 我创建了一个jQuery悬停按钮。 When you hover over the box, a jQuery button appears. 将鼠标悬停在框上时,将显示一个jQuery按钮。 However, it doesn't work. 但是,它不起作用。 Can someone show me how to add a black background to the box when hovered over? 有人可以向我展示如何将鼠标悬停在框上时添加黑色背景吗?

The objective is to; 目的是

  1. When rolling over the box, it displays "chart it btn" 将鼠标悬停在框上时,它会显示“ chart it btn”

  2. When rolling over the box, the box gets a black background. 将鼠标悬停在框上时,框会变成黑色背景。

jsFiddle jsFiddle

/*  CHART IT BTN ON POTS
===================================================================*/
$(".btn-trigger").hover(function () {
    $(this).find(".charthis-btn").show();
}, function () {
    $(this).find(".charthis-btn").hide();
})

I need the image that is shown to darken black with an opacity of 50% when rolled over. 我需要显示的图像,当鼠标滑过时显示为具有50%不透明度的黑色。

The FIDDLE 魔女

JS : JS:

$(".display-box").hover(function () {
$(this).find(".charthis-btn").show();
}, function () {
$(this).find(".charthis-btn").hide();
})

I'm not sure if it's what you want but try this: 我不确定这是否是您想要的,但是请尝试以下操作:

EDIT 编辑

DEMO 演示

$(".display-box").hover(function () {
    $(this).find(".charthis-btn").show();
    $(this).find(".hover-mask").fadeIn();
}, function () {
    $(this).find(".charthis-btn").hide();
    $(this).find(".hover-mask").fadeOut();
})
$(".display-box").hover(function () {
$(this).find(".charthis-btn").show();
}, function () {
$(this).find(".charthis-btn").hide();
})
$(".charthis-btn").on('mouseenter',function(){
$(".display-box img").css('opacity','0.5');
})
$(".charthis-btn").on('mouseout',function(){
$(".display-box img").css('opacity','');
})

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

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