Created
November 1, 2013 13:20
-
-
Save pixelchar/7265320 to your computer and use it in GitHub Desktop.
Stylish file upload using <label> to active an off-canvas file input field Source: http://jsfiddle.net/rudiedirkx/8hzjP/10/
This file contains hidden or 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
#picture { | |
position: absolute; | |
left: -9999px; | |
} | |
label { | |
cursor: pointer; | |
} |
This file contains hidden or 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
<form> | |
<label for="picture">Upload a Picture</label> | |
<input type="file" name="picture" id="picture"> | |
<span id="filename"></span> | |
</form> |
This file contains hidden or 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
$('#picture').change(function(e) { | |
var filepath = this.value; | |
var m = filepath.match(/([^\/\\]+)$/); | |
var filename = m[1]; | |
$('#filename').text(' -> ' + filename); | |
setTimeout((function(form) { | |
return function() { | |
form.submit(); | |
} | |
})(this.form), 1000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment