我正在使用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
不要忘记在方向更改时更新值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句