基本上,我有一个电子应用程序,我在其中添加了最小/关闭按钮 在加载时按钮可以正常工作,但在切换页面时使用平滑状态后,它们将停止工作 我找到了各种解决方案(github常见问题解答,stackoverlow等),但到目前为止都无济于事
按钮html
<div id="title-bar-btns">
<button class="btn btn-outline" id="min-btn">—</button>
<button class="btn btn-outline" id="close-btn">X</button>
</div>
main.js
$(function() {
'use strict';
var $page = $('#main'),
options = {
debug: !0,
prefetch: !0,
cacheLength: 4,
onStart: {
duration: 350,
render: function($container) {
$container.addClass('is-exiting');
smoothState.restartCSSAnimations()
}
},
onReady: {
duration: 0,
render: function($container, $newContent) {
$container.removeClass('is-exiting');
$container.html($newContent)
initfunction();
}
},
onAfter: function($container, $newContent) {
initfunction();
}
},
smoothState = $page.smoothState(options).data('smoothState')
});
$(document).ready(function() {
initfunction();
});
function initfunction() {
(function() {
const {
BrowserWindow
} = require('electron').remote
function init() {
document.getElementById("min-btn").addEventListener("click", (e) => {
var window = BrowserWindow.getFocusedWindow();
window.minimize()
});
document.getElementById("close-btn").addEventListener("click", (e) => {
var window = BrowserWindow.getFocusedWindow();
window.close()
})
};
document.onreadystatechange = () => {
if (document.readyState == "complete") {
init()
}
}
})()
}