Created
September 19, 2016 09:32
-
-
Save yaroslavKas/078ac76e3929e7c5d407ef8ff6dc766f to your computer and use it in GitHub Desktop.
Стилизация input "file"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="file_upload"> | |
<button type="button">Выбрать</button> | |
<div>Файл не выбран</div> | |
<input type="file"> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var wrapper = $( ".file_upload" ), | |
inp = wrapper.find( "input" ), | |
btn = wrapper.find( "button" ), | |
lbl = wrapper.find( "div" ); | |
var file_api = ( window.File && window.FileReader && window.FileList && window.Blob ) ? true : false; | |
inp.change(function(){ | |
var file_name; | |
if( file_api && inp[ 0 ].files[ 0 ] ) | |
file_name = inp[ 0 ].files[ 0 ].name; | |
else | |
file_name = inp.val().replace( "C:\\fakepath\\", '' ); | |
if( ! file_name.length ) | |
return; | |
if( lbl.is( ":visible" ) ){ | |
lbl.text( file_name ); | |
btn.text( "Выбрать" ); | |
}else | |
btn.text( file_name ); | |
}).change(); | |
$( window ).resize(function(){ | |
$( ".file_upload input" ).triggerHandler( "change" ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment