用canvas和js实现图像透明渐变,使用canvasImageGradient
我尝试使用这个简单的函数: http://code.google.com/p/canvasimagegradient/ 我必须用画布和js创建一个线性透明渐变(我的图像必须是动态的),但我的代码不起作用.. 你能告诉我哪里错了吗?
var ctx = $('#thecanvas')[0].getContext("2d");
var theImage= $('#theimage');
var linearGradient = ctx.createLinearGradient(0, 0, 0, theImage.height);
linearGradient.addColorStop(0, "transparent");
linearGradient.addColorStop(1, "#000");
ctx.drawImageGradient(theImage, 12, 65, linearGradient);
调试器只是告诉我: 控制台告诉我:
NOT_SUPPORTED_ERR: DOM Exception 9: The implementation did not support
就在这一行下:
var linearGradient = ctx.createLinearGradient(0, 0, 0, theImage.height);
提前非常感谢:)
im tryin to use this simple function:
http://code.google.com/p/canvasimagegradient/
i have to create a linear transparent gradient with canvas and js (my image must be dynamic) but my code it's not working..
can you tell me where im wrong?
var ctx = $('#thecanvas')[0].getContext("2d");
var theImage= $('#theimage');
var linearGradient = ctx.createLinearGradient(0, 0, 0, theImage.height);
linearGradient.addColorStop(0, "transparent");
linearGradient.addColorStop(1, "#000");
ctx.drawImageGradient(theImage, 12, 65, linearGradient);
the debugger just says me:
the console says me:
NOT_SUPPORTED_ERR: DOM Exception 9: The implementation did not support
just under this row:
var linearGradient = ctx.createLinearGradient(0, 0, 0, theImage.height);
thanks a lot in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是因为您将图像作为 jQuery 对象获取,其中高度是函数,而不是属性吗?所以你应该有
theImage.height()
,而不是theImage.height
?Is it because you are getting the image as a jQuery object, where height is a function, not a property? so you should have
theImage.height()
, nottheImage.height
?