Skip to content

Instantly share code, notes, and snippets.

@pixelchar
Created November 1, 2013 13:20
Show Gist options
  • Save pixelchar/7265320 to your computer and use it in GitHub Desktop.
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/
#picture {
position: absolute;
left: -9999px;
}
label {
cursor: pointer;
}
<form>
<label for="picture">Upload a Picture</label>
<input type="file" name="picture" id="picture">
<span id="filename"></span>
</form>
$('#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