我正在用appcelerator构建一个应用程序。我还在构建一个自定义幻灯片菜单。因此,如果你点击按钮,幻灯片菜单从左向右显示。
今天晚些时候我有了这个固定宽度的菜单。为了隐藏这个菜单,我设置了一个属性为-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有一个尺寸。
如果您的菜单视图宽度设置为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,隐藏时左值为-198
不要忘记在方向改变时更新值