share code upload đẹp

5 bài đăng
11.10.2016 / 13:07
mad
Bài đăng: 2434
Member
Nhào vô cắn tao đi, tao sợ mày à cắn bừa.
HTML5
  1. <a id="up_status" onclick="$('#input_frm').click();">Thêm ảnh</a>
  2. <input style="display:none" type="file" onchange="upload(this.files[0])" id="input_frm">
  3. <input type="hidden" id="data_image">
  4. <div class="data" style="display:block"></div>

JAVASCRIPT
  1. function upload(file){
  2. if(file.type.match(/image.*/)){
  3. var fd=new FormData;
  4. fd.append("image",file);
  5. var xhr=new XMLHttpRequest;
  6. $("#up_status").html("Đang tải lên");
  7. xhr.open("POST","http://rhash.tk/upload.php?domain=site");
  8. $(".data").append('<div class="image"><div class="progress"><div class="bar_load"></div></div></div>');
  9. xhr.upload.onprogress=function(t){
  10. $(".image:eq(-1) .bar_load").attr("style","width:"+t.loaded/t.total*100+"%")}
  11. xhr.onload=function(){
  12. var t=JSON.parse(xhr.responseText);
  13. $(".image:eq(-1)").append('<img src="'+t.link+' " >'),$(".image:eq(-1) img").load(function(){
  14. $(".image:eq(-1) .progress").fadeOut();
  15. $("#data_image").val($("#data_image").val()+"[img]"+t.link+"[/img]"),$("#up_status").html("Thêm ảnh");
  16. $("#input_frm").val("")
  17. });
  18. }
  19. xhr.send(fd);
  20. }
  21. }

CSS
  1. .data{
  2. display:block
  3. }
  4. .image{
  5. width: 60px;
  6. height: 60px;
  7. border: 1px solid #aaa;
  8. position: relative;
  9. background: #eee;
  10. display: inline-block;
  11. margin-right: 3px;
  12. }
  13. .image.complete .progress{
  14. display: none;
  15. }
  16. .progress{
  17. border: 1px solid #ddd;
  18. height: 10px;
  19. position: absolute;
  20. bottom: 3px;
  21. left: 3px;
  22. right: 3px;
  23. }
  24. .bar_load{
  25. background: #00dcff;
  26. height: 100%;
  27. width: 0%;
  28. transition: 0.2s all;
  29. box-shadow: -2px 0px 3px -1px #000 inset;
  30. }
  31. .image img{
  32. height: 100%;
  33. width: 100%;
  34. max-height: 100%;
  35. }

http://rhash.tk/upload.php?domain=site qua rhash.tk reg wap bạn rùi sửa vào

Đã chỉnh sửa. mad (11.10.2016 / 13:09)
11.10.2016 / 14:46
MnpNgok
Bài đăng: 51
Member
http://keyit.my.id

Hình như code thiếu thiếu cái j ý :15:

11.10.2016 / 16:11
mad
Bài đăng: 2434
Member
Nhào vô cắn tao đi, tao sợ mày à cắn bừa.

thieu jquery thi them vao

11.10.2016 / 16:27
Nhockutevy
Bài đăng: 355
Member

Cho luon jquery dj mad

11.10.2016 / 16:51
mad
Bài đăng: 2434
Member
Nhào vô cắn tao đi, tao sợ mày à cắn bừa.

jquery thi len gg co 1 dong thieu cha gi`?