uploadImg.gif

HTML部分

  1. <div class="container page-myComment">
  2. <div class="common-header">
  3. <a href="" class="goback ablock"><img src="../imgs/i_back.png" alt="" class="img"></a>
  4. <div class="title">意见反馈</div>
  5. <div class="share"></div>
  6. </div>
  7. <div class="feedback">
  8. <textarea class="textarea" placeholder="请详细描述您的问题,或者您有什么建议"></textarea>
  9. <div class="upload" id="pickimg_group"></div>
  10. <div class="upload">
  11. <div class="upload-icon">
  12. <input type="file" id="inputFile" accept="image/gif, image/jpeg" style="display: none;" onchange="changeAgentContent()">
  13. <input type="text" value="" disabled style="display: none;" id="inputFileAgent" />
  14. <input type="button" class="upload-input" id="upload" value="Browse..." />
  15. <img src="../imgs/camera.png" alt="" class="img">
  16. </div>
  17. <div class="upload-title">上传照片</div>
  18. </div>
  19. </div>
  20. <a href="" class="commit">提交</a>
  21. </div>

CSS部分

  1. .page-myComment {
  2. width: 100vw;
  3. height: 100vh;
  4. background-color: #fff;
  5. .feedback {
  6. width: 100vw;
  7. box-sizing: border-box;
  8. padding: 0 4.67vw;
  9. .textarea {
  10. width: 100%;
  11. height: 48vw;
  12. padding: 4.67vw 0;
  13. font-size: 3.73vw;
  14. line-height: 6vw;
  15. border-top: none;
  16. border-left: none;
  17. border-right: none;
  18. border-bottom: 1px solid #e2e2e2;
  19. outline: none;
  20. resize: none;
  21. }
  22. .upload {
  23. position: relative;
  24. margin-top: 4.67vw;
  25. display: flex;
  26. flex-direction: row;
  27. justify-content: flex-start;
  28. align-items: center;
  29. .upload-img {
  30. width: 13.33vw;
  31. height: 19.33vw;
  32. background-color: #ffffff;
  33. box-shadow: 0vw 0.4vw 1.33vw 0vw rgba(0, 0, 0, 0.1);
  34. border-radius: 0.53vw;
  35. overflow: hidden;
  36. line-height: 0;
  37. border: solid 0.27vw #e2e2e2;
  38. box-sizing: border-box;
  39. margin-right: 4vw;
  40. img {
  41. width: 13.33vw;
  42. height: 13.33vw;
  43. }
  44. .delete {
  45. border-top: 1px solid #e2e2e2;
  46. width: 13.33vw;
  47. height: 6vw;
  48. text-align: center;
  49. line-height: 4vw;
  50. color: #666;
  51. font-size: 3.2vw;
  52. }
  53. }
  54. .upload-icon {
  55. width: 13.33vw;
  56. height: 13.33vw;
  57. background-color: #ffffff;
  58. box-shadow: 0vw 0.4vw 1.33vw 0vw
  59. rgba(0, 0, 0, 0.1);
  60. border-radius: 0.53vw;
  61. overflow: hidden;
  62. line-height: 0;
  63. border: solid 0.27vw #e2e2e2;
  64. box-sizing: border-box;
  65. padding: 4vw 3.6vw;
  66. margin-right: 4vw;
  67. .upload-input {
  68. position: absolute;
  69. display: block;
  70. width: 13.33vw;
  71. height: 13.33vw;
  72. background-color: transparent;
  73. top: 0;
  74. left: 0;
  75. z-index: 1;
  76. outline: none;
  77. border: none;
  78. }
  79. }
  80. .upload-title {
  81. font-size: 3.73vw;
  82. color: #999999;
  83. }
  84. }
  85. }
  86. .commit {
  87. position: fixed;
  88. left: 0;
  89. bottom: 0;
  90. width: 100vw;
  91. height: 11.73vw;
  92. line-height: 11.73vw;
  93. text-align: center;
  94. font-size: 4.8vw;
  95. color: #fff;
  96. background-color: #9966b4;
  97. }
  98. }

JS部分

  1. $(function() {
  2. $('#upload').click(function() {
  3. document.getElementById('inputFile').click()
  4. });
  5. var pickimg_list = [];
  6. function changeAgentContent(){
  7. var value = $('#inputFile').val();
  8. console.log(value)
  9. $('#inputFileAgent').val(value);
  10. f = $('#inputFile')[0].files[0];
  11. var reads = new FileReader();
  12. reads.readAsDataURL(f); //
  13. reads.onload = function() {
  14. pickimg_list.push(this.result);
  15. renderImg();
  16. }
  17. // var formData = new FormData();
  18. // formData.append('file', f); //添加图片信息的参数
  19. // formData.append("name", $("#name").val());
  20. // common.showLoading();
  21. // $.ajax({
  22. // url: "/addons/mental/User/upload",
  23. // type: "post",
  24. // dataType: "json",
  25. // cache: false,
  26. // data: formData,
  27. // processData: false,// 不处理数据
  28. // contentType: false, // 不设置内容类型
  29. // success: function (data) {
  30. // console.log(data)
  31. // if (data.code == 1) {
  32. // pickimg_list.push(data.path);
  33. // renderImg();
  34. // }
  35. // },
  36. // complete: function() {
  37. // common.hideLoading();
  38. // }
  39. // })
  40. }
  41. function renderImg() {
  42. $('#pickimg_group').empty();
  43. if(pickimg_list.length >= 5) {
  44. $('.upload').eq(1).hide();
  45. }else {
  46. $('.upload').eq(1).show();
  47. }
  48. for(var i = 0, l = pickimg_list.length; i < l; i++) {
  49. $('#pickimg_group').append('<div class="upload-img"><img alt="" src="' + pickimg_list[i] + '"><div class="delete">删除</div>');
  50. }
  51. $('.delete').click(function() {
  52. var delete_index = $('.delete').index($(this));
  53. pickimg_list.splice(delete_index, 1);
  54. renderImg();
  55. })
  56. }
  57. })