Skip to content

Instantly share code, notes, and snippets.

@dmitry
Created June 9, 2009 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitry/126556 to your computer and use it in GitHub Desktop.
Save dmitry/126556 to your computer and use it in GitHub Desktop.
jQuery.fn.extend({
// options: width: integer, height: integer, image: string - absolute url path
// example: $("input[type='file']").stylizeFileInput({width: 79, height: 22, image: '/images/file_button.gif'});
stylizeFileInput: function(options) {
return this.each(function(){
var el = $(this);
var div = $('<div>');
div.css('width', options.width);
div.css('height', options.height);
div.css('background', 'url(' + options.image + ') 0 0 no-repeat');
div.css('overflow', 'hidden');
div.css('cursor', 'pointer');
div.css('position', 'relative');
el.wrap(div);
el.css('position', 'relative');
el.css('height', '100%');
el.css('width', 'auto');
el.css('cursor', 'pointer');
el.css('opacity', 0);
el.parent().mousemove(function(e) {
var currentTarget = $(e.currentTarget);
var file = $(currentTarget.children()[0]);
var offset = currentTarget.offset();
file.css('top', e.clientY - offset.top - (file.height() / 2));
file.css('left', e.clientX - offset.left - (file.width() - 30));
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment