Advertisement
afsarwebdev

Js input file upload button style

Jul 12th, 2018
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. //Input file button style
  2. //HTML
  3. <div class="file-upload">
  4. <div class="file-select">
  5. <div class="file-select-button" id="fileName">Choose File</div>
  6. <div class="file-select-name" id="noFile">No file chosen...</div>
  7. <input type="file" name="chooseFile" id="chooseFile">
  8. </div>
  9. </div>
  10. //CSS
  11.  
  12. .ic-file-upload input, label {
  13. display: block;
  14. }
  15.  
  16. .file-upload .file-select{
  17. display:block;
  18. color: #34495e;
  19. cursor:pointer;
  20. height:40px;
  21. line-height:40px;
  22. text-align:left;
  23. background:#FFFFFF;
  24. /* overflow:hidden; */
  25. position:relative;
  26. }
  27. .file-upload .file-select .file-select-button{
  28. background:#821789;
  29. padding:0 10px;
  30. display:inline-block;
  31. height:40px;
  32. line-height:40px;
  33. color: #fff;
  34. }
  35. .file-upload .file-select .file-select-name{
  36. line-height:40px;
  37. display:inline-block;
  38. padding:0 10px;
  39. }
  40. .file-upload .file-select:hover{
  41. border-color:#821789;
  42. transition:all .2s ease-in-out;
  43. -moz-transition:all .2s ease-in-out;
  44. -webkit-transition:all .2s ease-in-out;
  45. -o-transition:all .2s ease-in-out;
  46. }
  47. .file-upload .file-select:hover .file-select-button{
  48. background:#821789;
  49. color:#FFFFFF;
  50. transition:all .2s ease-in-out;
  51. -moz-transition:all .2s ease-in-out;
  52. -webkit-transition:all .2s ease-in-out;
  53. -o-transition:all .2s ease-in-out;
  54. }
  55. .file-upload.active .file-select{
  56. border-color:#3fa46a;
  57. transition:all .2s ease-in-out;
  58. -moz-transition:all .2s ease-in-out;
  59. -webkit-transition:all .2s ease-in-out;
  60. -o-transition:all .2s ease-in-out;
  61. white-space: nowrap;
  62. overflow: hidden;
  63. text-overflow: ellipsis;
  64. }
  65. .file-upload.active .file-select .file-select-button{
  66. background:#3fa46a;
  67. color:#FFFFFF;
  68. transition:all .2s ease-in-out;
  69. -moz-transition:all .2s ease-in-out;
  70. -webkit-transition:all .2s ease-in-out;
  71. -o-transition:all .2s ease-in-out;
  72. }
  73. .file-upload .file-select input[type=file]{
  74. z-index:100;
  75. cursor:pointer;
  76. position:absolute;
  77. height:100%;
  78. width:100%;
  79. top:0;
  80. left:0;
  81. opacity:0;
  82. filter:alpha(opacity=0);
  83. }
  84. .file-upload .file-select.file-select-disabled{
  85. opacity:0.65;
  86. }
  87. .file-upload .file-select.file-select-disabled:hover{
  88. cursor:default;
  89. display:block;
  90. border: 2px solid #821789;
  91. color: #34495e;
  92. cursor:pointer;
  93. height:40px;
  94. line-height:40px;
  95. margin-top:5px;
  96. text-align:left;
  97. background:#FFFFFF;
  98. overflow:hidden;
  99. position:relative;
  100. }
  101. .file-upload .file-select.file-select-disabled:hover .file-select-button{
  102. background:#821789;
  103. color:#666666;
  104. padding:0 10px;
  105. display:inline-block;
  106. height:40px;
  107. line-height:40px;
  108. }
  109. .file-upload .file-select.file-select-disabled:hover .file-select-name{
  110. line-height:40px;
  111. display:inline-block;
  112. padding:0 10px;
  113. }
  114.  
  115. //JS
  116. $('#chooseFile').bind('change', function () {
  117. var filename = $("#chooseFile").val();
  118. if (/^\s*$/.test(filename)) {
  119. $(".file-upload").removeClass('active');
  120. $("#noFile").text("No file chosen...");
  121. }
  122. else {
  123. $(".file-upload").addClass('active');
  124. $("#noFile").text(filename.replace("C:\\fakepath\\", ""));
  125. }
  126. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement