Created
December 19, 2012 14:49
-
-
Save dtex/4337176 to your computer and use it in GitHub Desktop.
Onion skinning plugin for jQuery
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
(function( $ ){ | |
var methods = { | |
init : function( options ) { | |
return this.each(function(){ | |
oSkin = $('<div class="onionSkin" style="width:100%;text-align:center;position:absolute;opacity:.5;display:none;" />'); | |
oImg = $('<img src="'+options.src+'" />'); | |
oImg.css(options.imgStyles); | |
oSkin.prepend(oImg); | |
$(this).prepend(oSkin); | |
$(window.document).keyup(function(e) { | |
// ctrl+o will toggle the onion skin | |
if (e.ctrlKey && e.which === 79) oSkin.toggle(); | |
// ctrl+1 through ctrl+9 will set the opacity | |
if (e.which >= 49 && e.which <= 57) { | |
oSkin.css('opacity', (e.which - 48) * .1); | |
} | |
}); | |
}); | |
} | |
}, oSkin; | |
$.fn.onion = function( method ) { | |
if ( methods[method] ) { | |
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 )); | |
} else if ( typeof method === 'object' || ! method ) { | |
return methods.init.apply( this, arguments ); | |
} else { | |
$.error( 'Method ' + method + ' does not exist on jQuery.onion' ); | |
} | |
}; | |
})( jQuery ); |
By default it has display none in the inline style... Why is that?
Nevermind, I think I understand now.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example: $("#onionSkinThis").onion({src: "img.png"});