page.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <html>
  2. <head>
  3. <meta charset="UTF-8">
  4. <title>JS模拟云信聊天界面</title>
  5. <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimal-ui" />
  6. <meta name="apple-mobile-web-app-capable" content="yes" />
  7. <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  8. <meta name="format-detection"content="telephone=no, email=no" />
  9. <style>
  10. /**重置标签默认样式*/
  11. * {
  12. color: #000000;
  13. margin: 0;
  14. padding: 0;
  15. list-style: none;
  16. font-family: '微软雅黑'
  17. }
  18. html,body{
  19. height:100%;
  20. }
  21. #container {
  22. width: 100%;
  23. height: 100%;
  24. background: #e9ecf0;
  25. margin: 0;
  26. position: relative;
  27. box-sizing: border-box;
  28. box-shadow: 20px 20px 55px #777;
  29. }
  30. .footer {
  31. width: 100%;
  32. height: 60px;
  33. background: #FFFFFF;
  34. position: absolute;
  35. bottom: 0;
  36. padding: 10px;
  37. box-sizing:border-box;
  38. }
  39. .footer input {
  40. width: 60%;
  41. height: 40px;
  42. outline: none;
  43. font-size: 14px;
  44. text-indent: 10px;
  45. position: absolute;
  46. border-radius: 6px;
  47. right: 80px;
  48. box-sizing: border-box;
  49. }
  50. .footer span {
  51. display: inline-block;
  52. width: 60px;
  53. height: 40px;
  54. background: #ccc;
  55. font-weight: 900;
  56. line-height: 45px;
  57. cursor: pointer;
  58. text-align: center;
  59. position: absolute;
  60. right: 10px;
  61. border-radius: 6px;
  62. top: 10px;
  63. }
  64. .footer span:hover {
  65. color: #fff;
  66. background: #999;
  67. }
  68. #icon {
  69. width: 40px;
  70. height: 40px;
  71. background-color: red;
  72. border-radius: 30px;
  73. float: left
  74. }
  75. img {
  76. width: 40px;
  77. height: 40px;
  78. }
  79. .content {
  80. font-size: 14px;
  81. width: 100%;
  82. height:100%;
  83. overflow: auto;
  84. padding: 10px 20px 80px;
  85. box-sizing: border-box;
  86. }
  87. .content li {
  88. width: 100%;
  89. display: block;
  90. clear: both;
  91. overflow: hidden;
  92. margin-top: 10px;
  93. }
  94. .content li img {
  95. float: left;
  96. }
  97. .content li span{
  98. background: #7cfc00;
  99. padding: 10px;
  100. border-radius: 10px;
  101. float: left;
  102. margin: 3px 10px 3px 10px;
  103. max-width: 310px;
  104. border: 1px solid #ccc;
  105. box-shadow: 0 0 3px #ccc;
  106. }
  107. .content li img.imgleft {
  108. float: left;
  109. }
  110. .content li img.imgright {
  111. float: right;
  112. }
  113. .content li span.spanleft {
  114. float: left;
  115. background: #fff;
  116. }
  117. .content li span.spanright {
  118. float: right;
  119. background: #3a9efb;
  120. }
  121. </style>
  122. <script>
  123. window.onload = function(){
  124. var arrIcon = new Array(2);//头像容器
  125. var num = 0; //控制头像改变
  126. var iNow = -1; //用来累加改变左右浮动
  127. var img = document.getElementById('img');
  128. arrIcon[0] = img.src;
  129. var btn = document.getElementById('btn');
  130. var text = document.getElementById('text');
  131. var content = document.getElementsByTagName('ul')[0];
  132. var span = content.getElementsByTagName('span');
  133. img.onclick = function(){
  134. JsBridge.picture({},function(data) {
  135. if (data.status == 200) {
  136. var base64 = data.values.image.base64;
  137. var width = data.values.image.width;
  138. var height = data.values.image.height;
  139. var w = 320.0;
  140. var h = (1.0*w*height)/width;
  141. // show
  142. img.src = "data:image/jpg;base64," + base64;
  143. img.width = w;
  144. img.height = h;
  145. if(num==0){
  146. arrIcon[1] = img.src;
  147. num = 1;
  148. }else if(num==1){
  149. arrIcon[0] = img.src;
  150. num = 0;
  151. }
  152. }else{
  153. console.log('"picture" bridge called failed; on response:' + JSON.stringify(data));
  154. }
  155. });
  156. }
  157. btn.onclick = function(){
  158. if(text.value ==''){
  159. alert('文本不能为空');
  160. }else {
  161. // js->java
  162. JsBridge.notification(text.value);
  163. content.innerHTML += '<li><img src="'+arrIcon[num]+'" class="imgTag"><span class="spanTag">'+text.value+'</span></li>';
  164. iNow++;
  165. var imgs = document.getElementsByClassName("imgTag");
  166. var spans = document.getElementsByClassName("spanTag");
  167. if(num==0){
  168. imgs[iNow].className = 'imgTag imgright';
  169. spans[iNow].className = 'spanTag spanright';
  170. }
  171. else {
  172. imgs[iNow].className = 'imgTag imgleft';
  173. spans[iNow].className = 'spanTag spanleft';
  174. }
  175. text.value ='';
  176. // 内容过多时,将滚动条放置到最底端
  177. contentcontent.scrollTop=content.scrollHeight;
  178. }
  179. }
  180. }
  181. </script>
  182. <script src="file:///android_asset/js/page.js"></script>
  183. </head>
  184. <body>
  185. <div id="container">
  186. <ul class="content">
  187. </ul>
  188. <div class="footer">
  189. <div id="icon">
  190. <img id="img" class="imgTag" src="file:///android_res/drawable/nim_avatar_default.png">
  191. </div>
  192. <input id="text" type="text" placeholder="说点什么吧...">
  193. <span id="btn">发送</span>
  194. </div>
  195. </div>
  196. </body>
  197. </html>