用与打开它的键相同的方式关闭GUI的最佳选择是什么jQuery

问题描述

因此,我正在尝试对现有的FiveM库存脚本进行一些编辑,以打开GUI并使用Javascript将其关闭

打开库存时

部分lua代码

if not IsPlayerDead(PlayerId()) then
            disableControlAction(0,37,true)
            if IsdisabledControlJustpressed(1,Config.OpenControl) and GetLastInputMethod(0) then 
            -- Config.OpenControl here is the same as the closing key which is ( TAB ↹ )
                    openInventory()

JavaScript代码段:

(我尝试添加一个变量,并在GUI打开时将其设置为True)

// var inventoryOpen = true;

window.addEventListener("message",function (event) {
    if (event.data.action == "display") {
        // inventoryOpen = true;
        type = event.data.type
        disabled = false;

(尝试在调用closeinventory()函数时将变量设置为false

function closeInventory() {
    $(".ui").fadeOut();
    $.post("http://pb-inventory/NUIFocusOff",JSON.stringify({}));
    // inventoryOpen = false;
}

(这是按下“关闭”键的时间)

$("body").on("keyup",function (key) {
        if (Config.closeKeys.includes(key.which)) { // Config.closeKeys here is 9 which is the TAB key ↹
            // if (inventoryOpen == true) {
                closeInventory();
            // }
        }
    });

因此,当我尝试上面的注释代码时,Gui开始出现毛刺,并在打开后保持关闭状态。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)