【问题标题】:Change background when mouse goes hover a button鼠标悬停按钮时更改背景
【发布时间】:2017-07-28 02:20:37
【问题描述】:

每次我将鼠标移到一个按钮上时,我都会尝试更改主页的背景图像,用于 5 个不同的按钮。

我正在尝试使用 Javascript,但它接缝不起作用,有什么帮助吗?

【问题讨论】:

  • 发布您的尝试。
  • 你做了什么?没有人会为你写代码。
  • 我们需要代码。
  • 代码已添加,谢谢。

标签: javascript css button background hover


【解决方案1】:

在这里,每当您悬停一个段落时,该段落的背景图像都会改变。

HTML 代码

 <p>Hover the mouse pointer over this paragraph.</p>

JQuery 代码

$("p").hover(function(){
        $(this).css("background-color", "yellow");
        }, function(){
        $(this).css("background-color", "pink");
    });

【讨论】:

  • 如果我必须指定背景图像所在的类的名称怎么办?它将是 .et_pb_section_0
【解决方案2】:

我尝试使用以下代码,但似乎没有任何反应;

$("et_pb_section_0").hover(function(){
        $(this).square0("background-color", "yellow");
        }, function(){
        $(this).square1("background-color", "pink");
    });

.et_pb_section_0 是背景的类,.square0、.square1 是按钮。

感谢您的帮助。

【讨论】:

    猜你喜欢
    • 2017-12-15
    • 2019-02-05
    • 2014-10-16
    • 2015-10-02
    • 1970-01-01
    • 1970-01-01
    • 2015-01-14
    • 2018-01-15
    • 1970-01-01
    相关资源
    最近更新 更多