简体   繁体   English

当我在 html 按钮上 hover 时,electron 中的单击事件不起作用且鼠标图标未更改?

[英]Click event in electron not working AND mouse icon not changing when I hover over a html button?

I'm working on a project using the electron framework.我正在使用 electron 框架进行项目。 I have an HTML file, a CSS file, and a Javascript file.我有一个 HTML 文件、一个 CSS 文件和一个 Javascript 文件。 The problem I'm having is that when I hover over a button, the hand pointer icon doesn't pop up even though I have given it the attribute to do so in my CSS code.我遇到的问题是,当我在按钮上使用 hover 时,即使我在 CSS 代码中为其赋予了这样做的属性,手形指针图标也不会弹出。

Here is my HTML code:这是我的 HTML 代码:

<button style="background: url(images/cross.svg);" alt="exit" id="exit_button"></button>

Here is my CSS code:这是我的 CSS 代码:

#exit_button{
    cursor: pointer;
    width: 15px;
    border: 0px;
    height: 15px;
    margin: 0%;
    padding: 0%;
    position: absolute;
    top: 5px;
    right: 5px;
}

And here is my Javascript code:这是我的 Javascript 代码:

//variables
const remote = require('electron').remote;

const exit_button = document.getElementById("exit_button");

//Firing functions
exit_button.addEventListener('click', close_window);

//functions
function close_window() {
    console.log("exit_button clicked, window closing..."); //This DOESN'T print
    var current_window = remote.getCurrentWindow();
    current_window.close();
};

The click event assigned to the exit_button isn't working either along with the pointer issue.分配给exit_button的点击事件也不能与指针问题一起工作。

Thanks in advance.提前致谢。

I tried putting your code in a JSFiddle and it worked without issue.我尝试将您的代码放在 JSFiddle 中,并且没有问题。 Maybe there's something else that's conflicting?也许还有其他一些矛盾的东西? Use developer tools and disable styles one by one to find the culprit.使用开发者工具,将styles一一禁用,找出罪魁祸首。

Ah, the problem was that I had啊,问题是我有

-webkit-user-select: none;
-webkit-app-region: drag;

In its parent.在其父。 This stopped me from clicking it.这阻止了我点击它。 I had to add the following in my css:我必须在我的 css 中添加以下内容:

-webkit-user-select: auto;
-webkit-app-region: no-drag;

And now my css looks like this:现在我的 css 看起来像这样:

#exit_button{
    cursor: pointer;
    border: 0px;
    width: 15px;
    height: auto;
    padding: 7.5px;
    position: absolute;
    top: 5px;
    right: 5px;
    -webkit-user-select: auto;
    -webkit-app-region: no-drag;
}

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

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