Guest User

Untitled

a guest
Dec 12th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. var win = Ti.UI.createWindow({
  2. backgroundColor: '#333'
  3. });
  4.  
  5. var menuWidth = 200;
  6.  
  7. var container = Ti.UI.createScrollView({
  8. disableBounce: false,
  9. horizontalBounce: true,
  10. contentWidth: Ti.Platform.displayCaps.platformWidth + menuWidth
  11. });
  12. container.contentOffset = { x: menuWidth, y: 0 };
  13.  
  14. var startX;
  15. container.addEventListener('dragStart', function (evt) {
  16. if (evt.source == container) {
  17. startX = evt.source.contentOffset.x;
  18. }
  19. });
  20. container.addEventListener('dragEnd', function (evt) {
  21. if (evt.source != container) {
  22. return;
  23. }
  24. var endX = evt.source.contentOffset.x;
  25. if (endX < 0 || endX > menuWidth) {
  26. // The scroll view itself will handle it.
  27. return;
  28. }
  29. var delta = startX - endX;
  30. Ti.API.info(endX);
  31. if (delta > 10) {
  32. openMenu();
  33. }
  34. else if (delta < -10) {
  35. closeMenu();
  36. }
  37. startX = null;
  38. });
  39.  
  40. function openMenu() {
  41. container.contentOffset = { x: 0, y: 0 };
  42. }
  43.  
  44. function closeMenu() {
  45. container.contentOffset = { x: menuWidth, y: 0 };
  46. }
  47.  
  48. var menu = Ti.UI.createScrollView({
  49. backgroundColor: '#123',
  50. left: 0,
  51. width: menuWidth,
  52. disableBounce: false,
  53. verticalBounce: true
  54. });
  55. menu.add(Ti.UI.createLabel({
  56. text: 'This is the super sexy menu.', textAlign: 'center',
  57. color: '#fff'
  58. }));
  59. container.add(menu);
  60.  
  61. var content = Ti.UI.createScrollView({
  62. backgroundColor: '#246',
  63. left: menuWidth,
  64. width: Ti.Platform.displayCaps.platformWidth,
  65. disableBounce: false,
  66. verticalBounce: true
  67. });
  68. content.add(Ti.UI.createLabel({
  69. text: 'This is the main content area.', textAlign: 'center',
  70. color: '#fff'
  71. }));
  72. var button = Ti.UI.createButton({
  73. title: 'Open Menu',
  74. top: 20, left: 20,
  75. width: 200, height: 40
  76. });
  77. button.addEventListener('click', openMenu);
  78. content.add(button);
  79. container.add(content);
  80.  
  81. win.add(container);
  82.  
  83. win.open();
Add Comment
Please, Sign In to add comment