Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. <div class="fileform">
  2. <input type="file" name="file" id="file" class="inputfile" data-multiple-caption="{count} files selected" multiple/>
  3. <label for="file">
  4. <i class="glyphicon glyphicon-paperclip"></i>
  5. <span class="file__choose">Выберите файл</span>
  6. </label>
  7. </div>
  8.  
  9. <script>
  10.  
  11. var inputs = document.querySelectorAll('.inputfile');
  12. Array.prototype.forEach.call(inputs, function(input){
  13. var label = input.nextElementSibling,
  14. labelVal = label.innerHTML;
  15. input.addEventListener('change', function(e){
  16. var fileName = '';
  17. if( this.files && this.files.length > 1 )
  18. fileName = ( this.getAttribute( 'data-multiple-caption' ) || '' ).replace( '{count}', this.files.length );
  19. else
  20. fileName = e.target.value.split( '\\' ).pop();
  21. if( fileName )
  22. label.querySelector( 'span' ).innerHTML = fileName;
  23. else
  24. label.innerHTML = labelVal;
  25. });
  26.  
  27. // фикс для firefox
  28. input.addEventListener('focus', function(){
  29. input.classList.add( 'has-focus' );
  30. });
  31. input.addEventListener('blur', function(){
  32. input.classList.remove( 'has-focus' );
  33. });
  34. });
  35.  
  36. </script>
  37.  
  38. <style>
  39. .fileform .file__choose {
  40. margin-left: 6px;
  41. }
  42.  
  43. .fileform #file {
  44. width: 0.1px;
  45. height: 0.1px;
  46. opacity: 0;
  47. overflow: hidden;
  48. position: absolute;
  49. z-index: -1;
  50. }
  51.  
  52. .fileform #file + label {
  53. display: -webkit-inline-box;
  54. display: -webkit-inline-flex;
  55. display: -ms-inline-flexbox;
  56. display: inline-flex;
  57. -webkit-box-align: center;
  58. -webkit-align-items: center;
  59. -ms-flex-align: center;
  60. align-items: center;
  61. padding: 4px 12px;
  62. cursor: pointer;
  63. font-size: 1.2em;
  64. font-weight: 500;
  65. -webkit-border-radius: 8px;
  66. border-radius: 8px;
  67. color: #484848;
  68. background: #f4f4f4;
  69. }
  70.  
  71. .fileform #file:focus + label,
  72. .fileform #file + label:hover {
  73. color: #fcfcfc;
  74. background-color: #5882b8;
  75. }
  76.  
  77. .fileform #file:focus + label {
  78. outline: 1px solid #d9625e;
  79. outline: -webkit-focus-ring-color auto 5px;
  80. }
  81.  
  82. .fileform #file + label * {
  83. pointer-events: none;
  84. }
  85. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement