index.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="page-view-size" content="1280*720">
  5. <meta name="format-detection" content="telephone=no">
  6. <meta charset="utf-8" />
  7. <title>小游戏测试</title>
  8. <link rel="stylesheet" type="text/css" href="css/base.css" />
  9. <link rel="stylesheet" type="text/css" href="css/index.css" />
  10. </head>
  11. <body>
  12. <div id="game_index" style="background: #FFFFFF;">
  13. <h1 id="title">小游戏测试项目</h1>
  14. <ul id="game_list">
  15. </ul>
  16. </div>
  17. <script type="text/javascript">
  18. // 页面适配
  19. var deviceWidth = window.innerWidth; //其它获取页面宽度代码,在某些盒子存在为0情况,所以选用此获取值方法。
  20. var deviceScale = deviceWidth / 1280;
  21. if (deviceWidth > 1280) {
  22. document.write('<meta name="viewport" content="width=1280,initial-scale=' + deviceScale + ', minimum-scale = ' +
  23. deviceScale + ', maximum-scale = ' + deviceScale + ', target-densitydpi=device-dpi">');
  24. } else {
  25. document.write('<meta name="viewport" content="width=1280, user-scalable=no">');
  26. }
  27. // 页面大小改变时刷新页面
  28. window.onresize = function() {
  29. window.location.reload();
  30. }
  31. var _ul = document.getElementById("game_list");
  32. var data = [{
  33. "pic": "<img src='img/icon/2048_icon.png'>",
  34. "title": "2048",
  35. "data_href": "../game/2048/index.html"
  36. }, {
  37. "pic": "",
  38. "title": "趣味英语测试",
  39. "data_href": "../game/EnglishTest/index.html"
  40. },
  41. // {
  42. // "pic": "",
  43. // "title": "",
  44. // "data_href": ""
  45. // },
  46. // {
  47. // "pic": "",
  48. // "title": "",
  49. // "data_href": ""
  50. // },
  51. // {
  52. // "pic": "",
  53. // "title": "",
  54. // "data_href": ""
  55. // },
  56. // {
  57. // "pic": "",
  58. // "title": "",
  59. // "data_href": ""
  60. // },
  61. // {
  62. // "pic": "",
  63. // "title": "",
  64. // "data_href": ""
  65. // },
  66. ]
  67. for (var i = 0; i < data.length; i++) {
  68. if(i==0){
  69. var current="current";
  70. }else{
  71. var current="";
  72. }
  73. var _li ="<li><div class='hotbutton "+current+"' data-view='"+i+"' data-href='"+data[i].data_href+"' data-id='"+i+"'><span class='pic'>"+data[i].pic+"</span><span class='title'>"+data[i].title+"</span></div></li>"
  74. _ul.innerHTML += _li;
  75. }
  76. document.onkeydown = function(event) {
  77. var _div = document.getElementsByClassName("current")[0];
  78. var _li = _div.parentElement;
  79. if (event.keyCode == 37 || event.keyCode == 38) { //左键 上键
  80. if (_div.getAttribute("data-id") != 0) {
  81. _div.className = "hotbutton";
  82. var prevEle = _li.previousSibling; //上一个
  83. prevEle.childNodes[0].className += " current"
  84. }
  85. } else if (event.keyCode == 39 || event.keyCode == 40) { //右键 下键
  86. if (_div.getAttribute("data-id") != data.length - 1) {
  87. _div.className = "hotbutton";
  88. var prevEle = _li.nextSibling; //下一个
  89. prevEle.childNodes[0].className += " current";
  90. }
  91. } else if (event.keyCode == 13) { //回车
  92. var data_href = _div.getAttribute("data-href");
  93. if (!data_href) {
  94. alert("不存在此项目!!!")
  95. } else {
  96. window.location.href = data_href;
  97. }
  98. }
  99. };
  100. </script>
  101. </body>
  102. </html>