dojotoolkit中DOM更新有轻微延迟

DOM updates with slight delay in dojotoolkit

本文关键字:轻微 延迟 更新 DOM dojotoolkit      更新时间:2023-09-26

我有一个dojox.mobile.IconMenu,上面有6个dojox.mobile.IconMenuItems。当我按下图标菜单项时,按钮应该被按进去。我通过简单地在适当的时间切换按钮的图像来实现这种行为。

现在出现的问题是:

在桌面(Chrome):当我只是点击按钮的视图变化如此之快,你不能看到新的,按下,图形!我必须按住按钮大约半秒钟,然后释放它,直到按钮显示新的图像。

在Android/iOS设备上(测试:Chrome, Firefox, Opera, Skyfire, Board Browser, Dolphin, Safari):按钮更改图像,但我看不到变化,因为图形更改速度太慢。

下面是代码(html)

<ul data-dojo-type="dojox.mobile.IconMenu" id="portalMenu" style="border: none; outline: none; background-image: url('../deliverables_800x480/backgrounds/img_bg_portal.gif'); position: absolute; z-index: 900; background-repeat: no-repeat; background-size: cover; height: 100%; width: 100%; top: 26px;">
<li label="IconMenuItem" data-dojo-type="dojox.mobile.IconMenuItem" id="portalButton1" icon="../deliverables_800x480/buttons/portal/btn_portal_freetext_big_normal.gif" style="border-top-color: transparent; border-right-color: transparent; border-bottom-color: transparent; border-left-color: transparent; line-height: 0px; text-align: center;" moveTo="null" onmousedown="toggleImg1()" onmousdown="toggleView1()"></li>

[其他按钮]

这里是我调用的函数(javascript):

onmousedown = " toggleImg1 ()

// press button1
// press button1
function toggleImg1(){  
    portalButton1.set("icon", "../deliverables_800x480/buttons/portal/btn_portal_freetext_big_armed.gif");
}
function toggleView1() {   
    portalButton1.set("moveTo", "messaging");
    portalButton1.set("selected", true);
    portalButton1.set("icon", "../deliverables_800x480/buttons/portal/btn_portal_freetext_big_normal.gif");
}

首先是不是有一个错误在你的标记?我看到onmousedown和onmousdown,不应该是onmousedown/onmouseup吗?

但是我认为你应该使用dojo/touch和listen to touch。按下/释放而不是鼠标向下/向上。这将确保您听触摸或鼠标,这取决于设备。

或者,也许你可以观察项目的"选定"状态,并在项目被选中时更改图标?比如:

item.watch("selected", function(){
    this.set("icon", this.selected?"selected.png":"deselected.png");
});

然后,让项目保持选中一段时间,你可以设置_selEndMethod="timer"。如果你愿意,你也可以改变_duration(默认为800,可能对你来说应该短一点)。