I am trying to write a simple jQuery plugin to check if the canvas is empty or not. However, I am having problems returning a boolean value.
(function ($) { $.fn.extend({ isBlank : function() { return this.each(function () { var context = this.getContext('2d'), imageData = context.getImageData(0, 0, this.offsetWidth, this.offsetHeight); for (var i = 0; i < imageData.data.length; i += 4) { if (imageData.data[i+3] !== 0) { return false; } } return true; }); } }); })(jQuery);
For some reason, this returns a canvas
object, not a boolean. However, when I take the code from each
loop, it returns a boolean value as expected.
How can I make this work with each
loop?
user1082754
source share