我正在使用 appcelerator 构建一个应用程序。我也在构建一个自定义幻灯片菜单。因此,如果您单击按钮,幻灯片菜单会从左到右出现。
今天晚些时候我有这个固定宽度的菜单。为了隐藏这个菜单,我设置了一个属性 left at -width。
现在我想用百分比设置菜单的宽度。但我不知道如何隐藏菜单。
这是我的 CSS 文件:
"#main_menu": {
layout: "vertical",
scrollType: "vertical",
showVerticalScrollIndicator: true,
top: 0,
left: 0,
width: "55%",
height: Ti.UI.FILL,
backgroundColor: "#70C662",
}
这是我的js文件
var menu_width = (Ti.Platform.displayCaps.platformWidth/2);
main_menu = Alloy.createController("_main_menu", args).getView();
$.sidebar.left = -menu_width;
但是menu_width的大小是不正确的,因为他的值是180,我的智能手机不可能有360px的尺寸。
如果您的菜单 View 的宽度设置为 55%,您需要存储该百分比的 dp 版本。
"#main_menu": {
width: "55%"
}
设备宽度:
var width = Ti.Platform.displayCaps.platformWidth;
//update this on orientation change
隐藏菜单:
$.main_menu.left = show ? 0 : -parseInt(width * 0.55));
如果设备宽度为360,则菜单宽度为198,隐藏时的left值为-198
不要忘记在方向更改时更新值。
我是一名优秀的程序员,十分优秀!